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