| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <ObjectHierarchy.hxx> |
| 21 |
#include <ObjectIdentifier.hxx> |
| 22 |
#include <ChartView.hxx> |
| 23 |
#include <Diagram.hxx> |
| 24 |
#include <RegressionCurveHelper.hxx> |
| 25 |
#include <RegressionCurveModel.hxx> |
| 26 |
#include <Axis.hxx> |
| 27 |
#include <AxisHelper.hxx> |
| 28 |
#include <ChartType.hxx> |
| 29 |
#include <ChartTypeHelper.hxx> |
| 30 |
#include <ChartModel.hxx> |
| 31 |
#include <DataSeries.hxx> |
| 32 |
#include <GridProperties.hxx> |
| 33 |
#include <LegendHelper.hxx> |
| 34 |
#include <chartview/DrawModelWrapper.hxx> |
| 35 |
#include <unonames.hxx> |
| 36 |
#include <BaseCoordinateSystem.hxx> |
| 37 |
|
| 38 |
#include <map> |
| 39 |
#include <algorithm> |
| 40 |
#include <cstddef> |
| 41 |
|
| 42 |
#include <com/sun/star/drawing/XShapes.hpp> |
| 43 |
#include <com/sun/star/chart/ErrorBarStyle.hpp> |
| 44 |
|
| 45 |
#include <com/sun/star/container/XIndexAccess.hpp> |
| 46 |
#include <com/sun/star/awt/Key.hpp> |
| 47 |
#include <com/sun/star/awt/KeyModifier.hpp> |
| 48 |
#include <utility> |
| 49 |
#include <comphelper/diagnose_ex.hxx> |
| 50 |
|
| 51 |
using namespace ::com::sun::star; |
| 52 |
using namespace ::com::sun::star::chart2; |
| 53 |
|
| 54 |
using ::com::sun::star::uno::Reference; |
| 55 |
|
| 56 |
namespace |
| 57 |
{ |
| 58 |
|
| 59 |
void lcl_getChildOIDs( |
| 60 |
::chart::ObjectHierarchy::tChildContainer& rOutChildren, |
| 61 |
const Reference< container::XIndexAccess >& xShapes ) |
| 62 |
{ |
| 63 |
if( !xShapes.is()) |
| 64 |
return; |
| 65 |
|
| 66 |
sal_Int32 nCount = xShapes->getCount(); |
| 67 |
for( sal_Int32 i=0; i<nCount; ++i) |
| 68 |
{ |
| 69 |
Reference< beans::XPropertySet > xShapeProp( xShapes->getByIndex( i ), uno::UNO_QUERY ); |
| 70 |
if( xShapeProp.is()) |
| 71 |
{ |
| 72 |
Reference< beans::XPropertySetInfo > xInfo( xShapeProp->getPropertySetInfo()); |
| 73 |
OUString aName; |
| 74 |
if( xInfo.is() && |
| 75 |
xInfo->hasPropertyByName( u"Name"_ustr) && |
| 76 |
(xShapeProp->getPropertyValue( u"Name"_ustr) >>= aName ) && |
| 77 |
!aName.isEmpty() && |
| 78 |
::chart::ObjectIdentifier::isCID( aName )) |
| 79 |
{ |
| 80 |
rOutChildren.emplace_back( aName ); |
| 81 |
} |
| 82 |
Reference< container::XIndexAccess > xNewShapes( xShapeProp, uno::UNO_QUERY ); |
| 83 |
if( xNewShapes.is()) |
| 84 |
lcl_getChildOIDs( rOutChildren, xNewShapes ); |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
void lcl_addAxisTitle( const rtl::Reference< ::chart::Axis >& xAxis, ::chart::ObjectHierarchy::tChildContainer& rContainer, const rtl::Reference<::chart::ChartModel>& xChartModel ) |
| 90 |
{ |
| 91 |
if( xAxis.is()) |
| 92 |
{ |
| 93 |
Reference< XTitle > xAxisTitle( xAxis->getTitleObject()); |
| 94 |
if( xAxisTitle.is()) |
| 95 |
rContainer.emplace_back( ::chart::ObjectIdentifier::createClassifiedIdentifierForObject( xAxisTitle, xChartModel ) ); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
} // anonymous namespace |
| 100 |
|
| 101 |
namespace chart |
| 102 |
{ |
| 103 |
|
| 104 |
void ObjectHierarchy::createTree( const rtl::Reference<::chart::ChartModel>& xChartDocument ) |
| 105 |
{ |
| 106 |
m_aChildMap.clear(); |
| 107 |
|
| 108 |
if( !xChartDocument.is() ) |
| 109 |
return; |
| 110 |
|
| 111 |
//@todo: change ObjectIdentifier to take an XChartDocument rather than XModel |
| 112 |
rtl::Reference< Diagram > xDiagram = xChartDocument->getFirstChartDiagram(); |
| 113 |
ObjectIdentifier aDiaOID; |
| 114 |
if( xDiagram.is() ) |
| 115 |
aDiaOID = ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierForObject( static_cast<cppu::OWeakObject*>(xDiagram.get()), xChartDocument ) ); |
| 116 |
tChildContainer aTopLevelContainer; |
| 117 |
|
| 118 |
// First Level |
| 119 |
|
| 120 |
// Chart Area |
| 121 |
if( m_bOrderingForElementSelector ) |
| 122 |
{ |
| 123 |
aTopLevelContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_PAGE, u"" ) ); |
| 124 |
if( xDiagram.is() ) |
| 125 |
{ |
| 126 |
aTopLevelContainer.push_back( aDiaOID ); |
| 127 |
createWallAndFloor( aTopLevelContainer, xDiagram ); |
| 128 |
createLegendTree( aTopLevelContainer, xChartDocument, xDiagram ); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
// Main Title |
| 133 |
Reference< XTitle > xMainTitle( xChartDocument->getTitleObject()); |
| 134 |
if( xMainTitle.is()) |
| 135 |
aTopLevelContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifierForObject( xMainTitle, xChartDocument ) ); |
| 136 |
|
| 137 |
if( xDiagram.is()) |
| 138 |
{ |
| 139 |
// Sub Title. Note: This is interpreted of being top level |
| 140 |
Reference< XTitle > xSubTitle( xDiagram->getTitleObject()); |
| 141 |
if( xSubTitle.is()) |
| 142 |
aTopLevelContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifierForObject( xSubTitle, xChartDocument ) ); |
| 143 |
|
| 144 |
if( !m_bOrderingForElementSelector ) |
| 145 |
{ |
| 146 |
// Axis Titles. Note: These are interpreted of being top level |
| 147 |
const std::vector< rtl::Reference< Axis > > aAxes = AxisHelper::getAllAxesOfDiagram( xDiagram ); |
| 148 |
for( rtl::Reference< Axis > const & axis : aAxes ) |
| 149 |
lcl_addAxisTitle( axis, aTopLevelContainer, xChartDocument ); |
| 150 |
|
| 151 |
// Diagram |
| 152 |
aTopLevelContainer.push_back( aDiaOID ); |
| 153 |
} |
| 154 |
|
| 155 |
if( m_bFlattenDiagram ) |
| 156 |
createDiagramTree( aTopLevelContainer, xChartDocument, xDiagram ); |
| 157 |
else |
| 158 |
{ |
| 159 |
tChildContainer aSubContainer; |
| 160 |
createDiagramTree( aSubContainer, xChartDocument, xDiagram ); |
| 161 |
if( !aSubContainer.empty() ) |
| 162 |
m_aChildMap[ aDiaOID ] = std::move(aSubContainer); |
| 163 |
} |
| 164 |
|
| 165 |
if( !m_bOrderingForElementSelector ) |
| 166 |
createLegendTree( aTopLevelContainer, xChartDocument, xDiagram ); |
| 167 |
} |
| 168 |
|
| 169 |
// #i12587# support for shapes in chart |
| 170 |
if ( !m_bOrderingForElementSelector ) |
| 171 |
{ |
| 172 |
createAdditionalShapesTree( aTopLevelContainer ); |
| 173 |
} |
| 174 |
|
| 175 |
// Chart Area |
| 176 |
if( !m_bOrderingForElementSelector ) |
| 177 |
aTopLevelContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_PAGE, u"" ) ); |
| 178 |
|
| 179 |
if( ! aTopLevelContainer.empty()) |
| 180 |
m_aChildMap[ObjectHierarchy::getRootNodeOID()] = std::move(aTopLevelContainer); |
| 181 |
} |
| 182 |
|
| 183 |
void ObjectHierarchy::createLegendTree( |
| 184 |
tChildContainer & rContainer, |
| 185 |
const rtl::Reference<::chart::ChartModel> & xChartDoc, |
| 186 |
const rtl::Reference< Diagram > & xDiagram ) |
| 187 |
{ |
| 188 |
if( !(xDiagram.is() && LegendHelper::hasLegend( xDiagram )) ) |
| 189 |
return; |
| 190 |
|
| 191 |
ObjectIdentifier aLegendOID( ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierForObject( xDiagram->getLegend(), xChartDoc ) ) ); |
| 192 |
rContainer.push_back( aLegendOID ); |
| 193 |
|
| 194 |
// iterate over child shapes of legend and search for matching CIDs |
| 195 |
if( m_pExplicitValueProvider ) |
| 196 |
{ |
| 197 |
rtl::Reference< SvxShapeGroupAnyD > xLegendShapeContainer = |
| 198 |
dynamic_cast<SvxShapeGroupAnyD*>( |
| 199 |
m_pExplicitValueProvider->getShapeForCID( aLegendOID.getObjectCID() ).get() ); |
| 200 |
tChildContainer aLegendEntryOIDs; |
| 201 |
lcl_getChildOIDs( aLegendEntryOIDs, xLegendShapeContainer ); |
| 202 |
|
| 203 |
m_aChildMap[aLegendOID] = std::move(aLegendEntryOIDs); |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
void ObjectHierarchy::createAxesTree( |
| 208 |
tChildContainer & rContainer, |
| 209 |
const rtl::Reference<::chart::ChartModel> & xChartDoc, |
| 210 |
const rtl::Reference< Diagram > & xDiagram ) |
| 211 |
{ |
| 212 |
sal_Int32 nDimensionCount = xDiagram->getDimension(); |
| 213 |
rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeByIndex( 0 ) ); |
| 214 |
bool bSupportsAxesGrids = true; |
| 215 |
if (xChartType.is()) |
| 216 |
bSupportsAxesGrids = xChartType->isSupportingMainAxis(nDimensionCount, 0); |
| 217 |
|
| 218 |
if (!bSupportsAxesGrids) |
| 219 |
return; |
| 220 |
|
| 221 |
// Data Table |
| 222 |
uno::Reference<chart2::XDataTable> xDataTable = xDiagram->getDataTable(); |
| 223 |
if (xDataTable.is()) |
| 224 |
{ |
| 225 |
rContainer.push_back(ObjectIdentifier::createClassifiedIdentifierForObject(xDataTable, xChartDoc)); |
| 226 |
} |
| 227 |
|
| 228 |
// Axes |
| 229 |
std::vector< rtl::Reference< Axis > > aAxes = AxisHelper::getAllAxesOfDiagram( xDiagram, /* bOnlyVisible = */ true ); |
| 230 |
if( !m_bOrderingForElementSelector ) |
| 231 |
{ |
| 232 |
for (const auto& rAxis : aAxes) |
| 233 |
rContainer.push_back( ObjectIdentifier::createClassifiedIdentifierForObject( rAxis, xChartDoc ) ); |
| 234 |
} |
| 235 |
|
| 236 |
// get all axes, also invisible ones |
| 237 |
aAxes = AxisHelper::getAllAxesOfDiagram( xDiagram ); |
| 238 |
// Grids |
| 239 |
for( rtl::Reference< Axis > const & xAxis : aAxes ) |
| 240 |
{ |
| 241 |
if(!xAxis.is()) |
| 242 |
continue; |
| 243 |
|
| 244 |
sal_Int32 nCooSysIndex = 0; |
| 245 |
sal_Int32 nDimensionIndex = 0; |
| 246 |
sal_Int32 nAxisIndex = 0; |
| 247 |
AxisHelper::getIndicesForAxis( xAxis, xDiagram, nCooSysIndex, nDimensionIndex, nAxisIndex ); |
| 248 |
if (nAxisIndex > 0 && !(xChartType.is() ? xChartType->isSupportingSecondaryAxis(nDimensionCount) : true)) |
| 249 |
continue; |
| 250 |
|
| 251 |
if( m_bOrderingForElementSelector ) |
| 252 |
{ |
| 253 |
// axis |
| 254 |
if( AxisHelper::isAxisVisible( xAxis ) ) |
| 255 |
rContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, xChartDoc ) ); |
| 256 |
|
| 257 |
// axis title |
| 258 |
lcl_addAxisTitle( xAxis, rContainer, xChartDoc ); |
| 259 |
} |
| 260 |
|
| 261 |
rtl::Reference< ::chart::GridProperties > xGridProperties( xAxis->getGridProperties2() ); |
| 262 |
if( AxisHelper::isGridVisible( xGridProperties ) ) |
| 263 |
{ |
| 264 |
//main grid |
| 265 |
rContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartDoc ) ); |
| 266 |
} |
| 267 |
|
| 268 |
std::vector< rtl::Reference< ::chart::GridProperties > > aSubGrids( xAxis->getSubGridProperties2() ); |
| 269 |
for( size_t nSubGrid = 0; nSubGrid < aSubGrids.size(); ++nSubGrid ) |
| 270 |
{ |
| 271 |
if( AxisHelper::isGridVisible( aSubGrids[nSubGrid] ) ) |
| 272 |
{ |
| 273 |
//sub grid |
| 274 |
rContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartDoc, nSubGrid ) ); |
| 275 |
} |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
void ObjectHierarchy::createWallAndFloor( |
| 281 |
tChildContainer & rContainer, |
| 282 |
const rtl::Reference< Diagram > & xDiagram ) |
| 283 |
{ |
| 284 |
sal_Int32 nDimensionCount = xDiagram->getDimension(); |
| 285 |
bool bIsThreeD = ( nDimensionCount == 3 ); |
| 286 |
bool bHasWall = xDiagram->isSupportingFloorAndWall(); |
| 287 |
if( bHasWall && bIsThreeD ) |
| 288 |
{ |
| 289 |
rContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, u"" ) ); |
| 290 |
|
| 291 |
Reference< beans::XPropertySet > xFloor( xDiagram->getFloor()); |
| 292 |
if( xFloor.is()) |
| 293 |
rContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_FLOOR, u"" ) ); |
| 294 |
} |
| 295 |
|
| 296 |
} |
| 297 |
|
| 298 |
void ObjectHierarchy::createDiagramTree( |
| 299 |
tChildContainer & rContainer, |
| 300 |
const rtl::Reference<::chart::ChartModel> & xChartDoc, |
| 301 |
const rtl::Reference< Diagram > & xDiagram ) |
| 302 |
{ |
| 303 |
if( !m_bOrderingForElementSelector ) |
| 304 |
{ |
| 305 |
createDataSeriesTree( rContainer, xDiagram ); |
| 306 |
createAxesTree( rContainer, xChartDoc, xDiagram ); |
| 307 |
createWallAndFloor( rContainer, xDiagram ); |
| 308 |
} |
| 309 |
else |
| 310 |
{ |
| 311 |
createAxesTree( rContainer, xChartDoc, xDiagram ); |
| 312 |
createDataSeriesTree( rContainer, xDiagram ); |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
void ObjectHierarchy::createDataSeriesTree( |
| 317 |
tChildContainer & rOutDiagramSubContainer, |
| 318 |
const rtl::Reference< Diagram > & xDiagram ) |
| 319 |
{ |
| 320 |
try |
| 321 |
{ |
| 322 |
sal_Int32 nDimensionCount = xDiagram->getDimension(); |
| 323 |
std::vector< rtl::Reference< BaseCoordinateSystem > > aCooSysSeq( |
| 324 |
xDiagram->getBaseCoordinateSystems()); |
| 325 |
for( std::size_t nCooSysIdx=0; nCooSysIdx<aCooSysSeq.size(); ++nCooSysIdx ) |
| 326 |
{ |
| 327 |
std::vector< rtl::Reference< ChartType > > aChartTypeSeq( aCooSysSeq[nCooSysIdx]->getChartTypes2()); |
| 328 |
for( std::size_t nCTIdx=0; nCTIdx<aChartTypeSeq.size(); ++nCTIdx ) |
| 329 |
{ |
| 330 |
const rtl::Reference< ChartType >& xChartType( aChartTypeSeq[nCTIdx] ); |
| 331 |
std::vector< rtl::Reference< DataSeries > > aSeriesSeq( xChartType->getDataSeries2() ); |
| 332 |
const sal_Int32 nNumberOfSeries = |
| 333 |
ChartTypeHelper::getNumberOfDisplayedSeries( xChartType, aSeriesSeq.size()); |
| 334 |
|
| 335 |
for( sal_Int32 nSeriesIdx=0; nSeriesIdx<nNumberOfSeries; ++nSeriesIdx ) |
| 336 |
{ |
| 337 |
OUString aSeriesParticle( |
| 338 |
ObjectIdentifier::createParticleForSeries( |
| 339 |
0, nCooSysIdx, nCTIdx, nSeriesIdx )); |
| 340 |
ObjectIdentifier aSeriesOID( |
| 341 |
ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierForParticle( aSeriesParticle ) ) ); |
| 342 |
rOutDiagramSubContainer.push_back( aSeriesOID ); |
| 343 |
|
| 344 |
tChildContainer aSeriesSubContainer; |
| 345 |
|
| 346 |
rtl::Reference< DataSeries > const & xSeries = aSeriesSeq[nSeriesIdx]; |
| 347 |
|
| 348 |
// data labels |
| 349 |
if( xSeries->hasDataLabelsAtSeries() ) |
| 350 |
{ |
| 351 |
OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" ); |
| 352 |
aSeriesSubContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifierForParticles( aSeriesParticle, aChildParticle ) ); |
| 353 |
} |
| 354 |
|
| 355 |
// Statistics |
| 356 |
if (xChartType.is() ? xChartType->isSupportingStatisticProperties(nDimensionCount) : true) |
| 357 |
{ |
| 358 |
const std::vector< rtl::Reference< RegressionCurveModel > > & rCurves( xSeries->getRegressionCurves2()); |
| 359 |
for( size_t nCurveIdx=0; nCurveIdx<rCurves.size(); ++nCurveIdx ) |
| 360 |
{ |
| 361 |
bool bIsAverageLine = RegressionCurveHelper::isMeanValueLine( rCurves[nCurveIdx] ); |
| 362 |
aSeriesSubContainer.emplace_back( ObjectIdentifier::createDataCurveCID( aSeriesParticle, nCurveIdx, bIsAverageLine ) ); |
| 363 |
if( RegressionCurveHelper::hasEquation( rCurves[nCurveIdx] ) ) |
| 364 |
{ |
| 365 |
aSeriesSubContainer.emplace_back( ObjectIdentifier::createDataCurveEquationCID( aSeriesParticle, nCurveIdx ) ); |
| 366 |
} |
| 367 |
} |
| 368 |
Reference< beans::XPropertySet > xErrorBarProp; |
| 369 |
if( (xSeries->getPropertyValue( CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarProp) && |
| 370 |
xErrorBarProp.is()) |
| 371 |
{ |
| 372 |
sal_Int32 nStyle = css::chart::ErrorBarStyle::NONE; |
| 373 |
if( ( xErrorBarProp->getPropertyValue( u"ErrorBarStyle"_ustr) >>= nStyle ) && |
| 374 |
( nStyle != css::chart::ErrorBarStyle::NONE ) ) |
| 375 |
{ |
| 376 |
aSeriesSubContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifierWithParent( |
| 377 |
OBJECTTYPE_DATA_ERRORS_Y, u"", aSeriesParticle ) ); |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
if( (xSeries->getPropertyValue(CHART_UNONAME_ERRORBAR_X) >>= xErrorBarProp) && |
| 382 |
xErrorBarProp.is()) |
| 383 |
{ |
| 384 |
sal_Int32 nStyle = css::chart::ErrorBarStyle::NONE; |
| 385 |
if( ( xErrorBarProp->getPropertyValue( u"ErrorBarStyle"_ustr) >>= nStyle ) && |
| 386 |
( nStyle != css::chart::ErrorBarStyle::NONE ) ) |
| 387 |
{ |
| 388 |
aSeriesSubContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifierWithParent( |
| 389 |
OBJECTTYPE_DATA_ERRORS_X, u"", aSeriesParticle ) ); |
| 390 |
} |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
// Data Points |
| 395 |
// iterate over child shapes of legend and search for matching CIDs |
| 396 |
if( m_pExplicitValueProvider ) |
| 397 |
{ |
| 398 |
rtl::Reference< SvxShapeGroupAnyD > xSeriesShapeContainer = |
| 399 |
dynamic_cast<SvxShapeGroupAnyD*>( |
| 400 |
m_pExplicitValueProvider->getShapeForCID( aSeriesOID.getObjectCID() ).get() ); |
| 401 |
lcl_getChildOIDs( aSeriesSubContainer, xSeriesShapeContainer ); |
| 402 |
} |
| 403 |
|
| 404 |
if( ! aSeriesSubContainer.empty()) |
| 405 |
m_aChildMap[ aSeriesOID ] = std::move(aSeriesSubContainer); |
| 406 |
} |
| 407 |
} |
| 408 |
} |
| 409 |
} |
| 410 |
catch( const uno::Exception & ) |
| 411 |
{ |
| 412 |
DBG_UNHANDLED_EXCEPTION("chart2"); |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
void ObjectHierarchy::createAdditionalShapesTree(tChildContainer& rContainer) |
| 417 |
{ |
| 418 |
try |
| 419 |
{ |
| 420 |
if ( m_pExplicitValueProvider ) |
| 421 |
{ |
| 422 |
rtl::Reference<SvxDrawPage> xDrawPage( m_pExplicitValueProvider->getDrawModelWrapper()->getMainDrawPage() ); |
| 423 |
Reference< drawing::XShapes > xChartRoot( DrawModelWrapper::getChartRootShape( xDrawPage ) ); |
| 424 |
sal_Int32 nCount = xDrawPage->getCount(); |
| 425 |
for ( sal_Int32 i = 0; i < nCount; ++i ) |
| 426 |
{ |
| 427 |
Reference< drawing::XShape > xShape; |
| 428 |
if ( xDrawPage->getByIndex( i ) >>= xShape ) |
| 429 |
{ |
| 430 |
if ( xShape.is() && xShape != xChartRoot ) |
| 431 |
{ |
| 432 |
rContainer.emplace_back( xShape ); |
| 433 |
} |
| 434 |
} |
| 435 |
} |
| 436 |
} |
| 437 |
} |
| 438 |
catch ( const uno::Exception& ) |
| 439 |
{ |
| 440 |
DBG_UNHANDLED_EXCEPTION("chart2"); |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
bool ObjectHierarchy::hasChildren( const ObjectIdentifier& rParent ) const |
| 445 |
{ |
| 446 |
if ( rParent.isValid() ) |
| 447 |
{ |
| 448 |
tChildMap::const_iterator aIt( m_aChildMap.find( rParent )); |
| 449 |
if( aIt != m_aChildMap.end()) |
| 450 |
return ! (aIt->second.empty()); |
| 451 |
} |
| 452 |
return false; |
| 453 |
} |
| 454 |
|
| 455 |
const ObjectHierarchy::tChildContainer & ObjectHierarchy::getChildren( const ObjectIdentifier& rParent ) const |
| 456 |
{ |
| 457 |
if ( rParent.isValid() ) |
| 458 |
{ |
| 459 |
tChildMap::const_iterator aIt( m_aChildMap.find( rParent )); |
| 460 |
if( aIt != m_aChildMap.end()) |
| 461 |
return aIt->second; |
| 462 |
} |
| 463 |
static const tChildContainer EMPTY; |
| 464 |
return EMPTY; |
| 465 |
} |
| 466 |
|
| 467 |
const ObjectHierarchy::tChildContainer & ObjectHierarchy::getSiblings( const ObjectIdentifier& rNode ) const |
| 468 |
{ |
| 469 |
if ( rNode.isValid() && !ObjectHierarchy::isRootNode( rNode ) ) |
| 470 |
{ |
| 471 |
for (auto const& child : m_aChildMap) |
| 472 |
{ |
| 473 |
tChildContainer::const_iterator aElemIt( |
| 474 |
std::find( child.second.begin(), child.second.end(), rNode )); |
| 475 |
if( aElemIt != child.second.end()) |
| 476 |
return child.second; |
| 477 |
} |
| 478 |
} |
| 479 |
static const tChildContainer EMPTY; |
| 480 |
return EMPTY; |
| 481 |
} |
| 482 |
|
| 483 |
ObjectIdentifier ObjectHierarchy::getParentImpl( |
| 484 |
const ObjectIdentifier & rParentOID, |
| 485 |
const ObjectIdentifier & rOID ) const |
| 486 |
{ |
| 487 |
// search children |
| 488 |
tChildContainer aChildren( getChildren( rParentOID )); |
| 489 |
tChildContainer::const_iterator aIt( |
| 490 |
std::find( aChildren.begin(), aChildren.end(), rOID )); |
| 491 |
// recursion end |
| 492 |
if( aIt != aChildren.end()) |
| 493 |
return rParentOID; |
| 494 |
|
| 495 |
for (auto const& child : aChildren) |
| 496 |
{ |
| 497 |
// recursion |
| 498 |
ObjectIdentifier aTempParent( getParentImpl( child, rOID )); |
| 499 |
if ( aTempParent.isValid() ) |
| 500 |
{ |
| 501 |
// exit on success |
| 502 |
return aTempParent; |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
// exit on fail |
| 507 |
return ObjectIdentifier(); |
| 508 |
} |
| 509 |
|
| 510 |
ObjectIdentifier ObjectHierarchy::getParent( |
| 511 |
const ObjectIdentifier & rOID ) const |
| 512 |
{ |
| 513 |
return getParentImpl( ObjectHierarchy::getRootNodeOID(), rOID ); |
| 514 |
} |
| 515 |
|
| 516 |
ObjectHierarchy::ObjectHierarchy( |
| 517 |
const rtl::Reference<::chart::ChartModel> & xChartDocument, |
| 518 |
ChartView * pExplicitValueProvider /* = 0 */, |
| 519 |
bool bFlattenDiagram /* = false */, |
| 520 |
bool bOrderingForElementSelector /* = false */) : |
| 521 |
m_pExplicitValueProvider( pExplicitValueProvider ), |
| 522 |
m_bFlattenDiagram( bFlattenDiagram ), |
| 523 |
m_bOrderingForElementSelector( bOrderingForElementSelector ) |
| 524 |
{ |
| 525 |
createTree( xChartDocument ); |
| 526 |
// don't remember this helper to avoid access after lifetime |
| 527 |
m_pExplicitValueProvider = nullptr; |
| 528 |
} |
| 529 |
|
| 530 |
ObjectHierarchy::~ObjectHierarchy() |
| 531 |
{} |
| 532 |
|
| 533 |
ObjectIdentifier ObjectHierarchy::getRootNodeOID() |
| 534 |
{ |
| 535 |
return ObjectIdentifier( u"ROOT"_ustr ); |
| 536 |
} |
| 537 |
|
| 538 |
bool ObjectHierarchy::isRootNode( const ObjectIdentifier& rOID ) |
| 539 |
{ |
| 540 |
return ( rOID == ObjectHierarchy::getRootNodeOID() ); |
| 541 |
} |
| 542 |
|
| 543 |
const ObjectHierarchy::tChildContainer & ObjectHierarchy::getTopLevelChildren() const |
| 544 |
{ |
| 545 |
return getChildren( ObjectHierarchy::getRootNodeOID()); |
| 546 |
} |
| 547 |
|
| 548 |
sal_Int32 ObjectHierarchy::getIndexInParent( |
| 549 |
const ObjectIdentifier& rNode ) const |
| 550 |
{ |
| 551 |
ObjectIdentifier aParentOID( getParent( rNode )); |
| 552 |
const tChildContainer & aChildren( getChildren( aParentOID ) ); |
| 553 |
sal_Int32 nIndex = 0; |
| 554 |
for (auto const& child : aChildren) |
| 555 |
{ |
| 556 |
if ( child == rNode ) |
| 557 |
return nIndex; |
| 558 |
++nIndex; |
| 559 |
} |
| 560 |
return -1; |
| 561 |
} |
| 562 |
|
| 563 |
ObjectKeyNavigation::ObjectKeyNavigation( |
| 564 |
ObjectIdentifier aCurrentOID, |
| 565 |
rtl::Reference<::chart::ChartModel> xChartDocument, |
| 566 |
ChartView * pExplicitValueProvider /* = 0 */ ) : |
| 567 |
m_aCurrentOID(std::move( aCurrentOID )), |
| 568 |
m_xChartDocument(std::move( xChartDocument )), |
| 569 |
m_pExplicitValueProvider( pExplicitValueProvider ) |
| 570 |
{ |
| 571 |
if ( !m_aCurrentOID.isValid() ) |
| 572 |
{ |
| 573 |
setCurrentSelection( ObjectHierarchy::getRootNodeOID() ); |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
bool ObjectKeyNavigation::handleKeyEvent( |
| 578 |
const awt::KeyEvent & rEvent ) |
| 579 |
{ |
| 580 |
bool bResult = false; |
| 581 |
|
| 582 |
switch( rEvent.KeyCode ) |
| 583 |
{ |
| 584 |
case awt::Key::TAB: |
| 585 |
if( rEvent.Modifiers & awt::KeyModifier::SHIFT ) |
| 586 |
bResult = previous(); |
| 587 |
else |
| 588 |
bResult = next(); |
| 589 |
break; |
| 590 |
case awt::Key::HOME: |
| 591 |
bResult = first(); |
| 592 |
break; |
| 593 |
case awt::Key::END: |
| 594 |
bResult = last(); |
| 595 |
break; |
| 596 |
case awt::Key::F3: |
| 597 |
if( rEvent.Modifiers & awt::KeyModifier::SHIFT ) |
| 598 |
bResult = up(); |
| 599 |
else |
| 600 |
bResult = down(); |
| 601 |
break; |
| 602 |
case awt::Key::ESCAPE: |
| 603 |
setCurrentSelection( ObjectIdentifier() ); |
| 604 |
bResult = true; |
| 605 |
break; |
| 606 |
default: |
| 607 |
bResult = false; |
| 608 |
break; |
| 609 |
} |
| 610 |
return bResult; |
| 611 |
} |
| 612 |
|
| 613 |
void ObjectKeyNavigation::setCurrentSelection( const ObjectIdentifier& rOID ) |
| 614 |
{ |
| 615 |
m_aCurrentOID = rOID; |
| 616 |
} |
| 617 |
|
| 618 |
bool ObjectKeyNavigation::first() |
| 619 |
{ |
| 620 |
ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider ); |
| 621 |
const ObjectHierarchy::tChildContainer& aSiblings( aHierarchy.getSiblings( getCurrentSelection() ) ); |
| 622 |
bool bResult = !aSiblings.empty(); |
| 623 |
if( bResult ) |
| 624 |
setCurrentSelection( aSiblings.front()); |
| 625 |
else |
| 626 |
bResult = veryFirst(); |
| 627 |
return bResult; |
| 628 |
} |
| 629 |
|
| 630 |
bool ObjectKeyNavigation::last() |
| 631 |
{ |
| 632 |
ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider ); |
| 633 |
const ObjectHierarchy::tChildContainer& aSiblings( aHierarchy.getSiblings( getCurrentSelection() ) ); |
| 634 |
bool bResult = !aSiblings.empty(); |
| 635 |
if( bResult ) |
| 636 |
setCurrentSelection( aSiblings.back()); |
| 637 |
else |
| 638 |
bResult = veryLast(); |
| 639 |
return bResult; |
| 640 |
} |
| 641 |
|
| 642 |
bool ObjectKeyNavigation::next() |
| 643 |
{ |
| 644 |
ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider ); |
| 645 |
ObjectHierarchy::tChildContainer aSiblings( aHierarchy.getSiblings( getCurrentSelection() ) ); |
| 646 |
bool bResult = !aSiblings.empty(); |
| 647 |
if( bResult ) |
| 648 |
{ |
| 649 |
ObjectHierarchy::tChildContainer::const_iterator aIt( |
| 650 |
std::find( aSiblings.begin(), aSiblings.end(), getCurrentSelection())); |
| 651 |
assert(aIt != aSiblings.end()); |
| 652 |
if( ++aIt == aSiblings.end()) |
| 653 |
aIt = aSiblings.begin(); |
| 654 |
setCurrentSelection( *aIt ); |
| 655 |
} |
| 656 |
else |
| 657 |
bResult = veryFirst(); |
| 658 |
|
| 659 |
return bResult; |
| 660 |
} |
| 661 |
|
| 662 |
bool ObjectKeyNavigation::previous() |
| 663 |
{ |
| 664 |
ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider ); |
| 665 |
ObjectHierarchy::tChildContainer aSiblings( aHierarchy.getSiblings( getCurrentSelection())); |
| 666 |
bool bResult = !aSiblings.empty(); |
| 667 |
if( bResult ) |
| 668 |
{ |
| 669 |
ObjectHierarchy::tChildContainer::const_iterator aIt( |
| 670 |
std::find( aSiblings.begin(), aSiblings.end(), getCurrentSelection())); |
| 671 |
OSL_ASSERT( aIt != aSiblings.end()); |
| 672 |
if( aIt == aSiblings.begin()) |
| 673 |
aIt = aSiblings.end(); |
| 674 |
--aIt; |
| 675 |
setCurrentSelection( *aIt ); |
| 676 |
} |
| 677 |
else |
| 678 |
bResult = veryLast(); |
| 679 |
return bResult; |
| 680 |
} |
| 681 |
|
| 682 |
bool ObjectKeyNavigation::up() |
| 683 |
{ |
| 684 |
ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider ); |
| 685 |
bool bResult = !ObjectHierarchy::isRootNode( getCurrentSelection()); |
| 686 |
if( bResult ) |
| 687 |
setCurrentSelection( aHierarchy.getParent( getCurrentSelection())); |
| 688 |
return bResult; |
| 689 |
} |
| 690 |
|
| 691 |
bool ObjectKeyNavigation::down() |
| 692 |
{ |
| 693 |
ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider ); |
| 694 |
bool bResult = aHierarchy.hasChildren( getCurrentSelection()); |
| 695 |
if( bResult ) |
| 696 |
{ |
| 697 |
const ObjectHierarchy::tChildContainer& aChildren = aHierarchy.getChildren( getCurrentSelection()); |
| 698 |
OSL_ASSERT( !aChildren.empty()); |
| 699 |
setCurrentSelection( aChildren.front()); |
| 700 |
} |
| 701 |
return bResult; |
| 702 |
} |
| 703 |
|
| 704 |
bool ObjectKeyNavigation::veryFirst() |
| 705 |
{ |
| 706 |
ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider ); |
| 707 |
const ObjectHierarchy::tChildContainer& aChildren( aHierarchy.getTopLevelChildren()); |
| 708 |
bool bResult = !aChildren.empty(); |
| 709 |
if( bResult ) |
| 710 |
setCurrentSelection( aChildren.front()); |
| 711 |
return bResult; |
| 712 |
} |
| 713 |
|
| 714 |
bool ObjectKeyNavigation::veryLast() |
| 715 |
{ |
| 716 |
ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider ); |
| 717 |
const ObjectHierarchy::tChildContainer& aChildren( aHierarchy.getTopLevelChildren()); |
| 718 |
bool bResult = !aChildren.empty(); |
| 719 |
if( bResult ) |
| 720 |
setCurrentSelection( aChildren.back()); |
| 721 |
return bResult; |
| 722 |
} |
| 723 |
|
| 724 |
} // namespace chart |
| 725 |
|
| 726 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |