1*cde9e8dcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*cde9e8dcSAndrew Rist * distributed with this work for additional information 6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance 9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at 10*cde9e8dcSAndrew Rist * 11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*cde9e8dcSAndrew Rist * 13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an 15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the 17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations 18*cde9e8dcSAndrew Rist * under the License. 19*cde9e8dcSAndrew Rist * 20*cde9e8dcSAndrew Rist *************************************************************/ 21*cde9e8dcSAndrew Rist 22*cde9e8dcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_chart2.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "RangeHighlighter.hxx" 28cdf0e10cSrcweir #include "WeakListenerAdapter.hxx" 29cdf0e10cSrcweir #include "ChartModelHelper.hxx" 30cdf0e10cSrcweir #include "DataSourceHelper.hxx" 31cdf0e10cSrcweir #include "ContainerHelper.hxx" 32cdf0e10cSrcweir #include "macros.hxx" 33cdf0e10cSrcweir #include "ObjectIdentifier.hxx" 34cdf0e10cSrcweir #include "DataSeriesHelper.hxx" 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeries.hpp> 37cdf0e10cSrcweir #include <com/sun/star/chart/ErrorBarStyle.hpp> 38cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp> 39cdf0e10cSrcweir 40cdf0e10cSrcweir #define PREFERED_DEFAULT_COLOR 0x0000ff 41cdf0e10cSrcweir 42cdf0e10cSrcweir using namespace ::com::sun::star; 43cdf0e10cSrcweir 44cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 45cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 46cdf0e10cSrcweir using ::rtl::OUString; 47cdf0e10cSrcweir 48cdf0e10cSrcweir namespace 49cdf0e10cSrcweir { 50cdf0e10cSrcweir 51cdf0e10cSrcweir void lcl_fillRanges( 52cdf0e10cSrcweir Sequence< chart2::data::HighlightedRange > & rOutRanges, 53cdf0e10cSrcweir Sequence< OUString > aRangeStrings, 54cdf0e10cSrcweir sal_Int32 nPreferredColor = PREFERED_DEFAULT_COLOR, 55cdf0e10cSrcweir sal_Int32 nIndex = -1 ) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir rOutRanges.realloc( aRangeStrings.getLength()); 58cdf0e10cSrcweir for( sal_Int32 i=0; i<aRangeStrings.getLength(); ++i ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir rOutRanges[i].RangeRepresentation = aRangeStrings[i]; 61cdf0e10cSrcweir rOutRanges[i].PreferredColor = nPreferredColor; 62cdf0e10cSrcweir rOutRanges[i].AllowMerginigWithOtherRanges = sal_False; 63cdf0e10cSrcweir rOutRanges[i].Index = nIndex; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir } // anonymous namespace 68cdf0e10cSrcweir 69cdf0e10cSrcweir namespace chart 70cdf0e10cSrcweir { 71cdf0e10cSrcweir 72cdf0e10cSrcweir RangeHighlighter::RangeHighlighter( 73cdf0e10cSrcweir const Reference< view::XSelectionSupplier > & xSelectionSupplier ) : 74cdf0e10cSrcweir impl::RangeHighlighter_Base( m_aMutex ), 75cdf0e10cSrcweir m_xSelectionSupplier( xSelectionSupplier ), 76cdf0e10cSrcweir m_nAddedListenerCount( 0 ), 77cdf0e10cSrcweir m_bIncludeHiddenCells(true) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir RangeHighlighter::~RangeHighlighter() 82cdf0e10cSrcweir {} 83cdf0e10cSrcweir 84cdf0e10cSrcweir // ____ XRangeHighlighter ____ 85cdf0e10cSrcweir Sequence< chart2::data::HighlightedRange > SAL_CALL RangeHighlighter::getSelectedRanges() 86cdf0e10cSrcweir throw (uno::RuntimeException) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir return m_aSelectedRanges; 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir void RangeHighlighter::determineRanges() 92cdf0e10cSrcweir { 93cdf0e10cSrcweir m_aSelectedRanges.realloc( 0 ); 94cdf0e10cSrcweir if( m_xSelectionSupplier.is()) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir try 97cdf0e10cSrcweir { 98cdf0e10cSrcweir Reference< frame::XController > xController( m_xSelectionSupplier, uno::UNO_QUERY ); 99cdf0e10cSrcweir Reference< frame::XModel > xChartModel; 100cdf0e10cSrcweir if( xController.is()) 101cdf0e10cSrcweir xChartModel.set( xController->getModel()); 102cdf0e10cSrcweir 103cdf0e10cSrcweir m_bIncludeHiddenCells = ChartModelHelper::isIncludeHiddenCells( xChartModel ); 104cdf0e10cSrcweir 105cdf0e10cSrcweir uno::Any aSelection( m_xSelectionSupplier->getSelection()); 106cdf0e10cSrcweir const uno::Type& rType = aSelection.getValueType(); 107cdf0e10cSrcweir 108cdf0e10cSrcweir if ( rType == ::getCppuType( static_cast< const OUString* >( 0 ) ) ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir // @todo??: maybe getSelection() should return a model object rather than a CID 111cdf0e10cSrcweir 112cdf0e10cSrcweir OUString aCID; 113cdf0e10cSrcweir aSelection >>= aCID; 114cdf0e10cSrcweir if ( aCID.getLength() > 0 ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir ObjectType eObjectType = ObjectIdentifier::getObjectType( aCID ); 117cdf0e10cSrcweir sal_Int32 nIndex = ObjectIdentifier::getIndexFromParticleOrCID( aCID ); 118cdf0e10cSrcweir Reference< chart2::XDataSeries > xDataSeries( ObjectIdentifier::getDataSeriesForCID( aCID, xChartModel ) ); 119cdf0e10cSrcweir if( OBJECTTYPE_LEGEND_ENTRY == eObjectType ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir OUString aParentParticel( ObjectIdentifier::getFullParentParticle( aCID ) ); 122cdf0e10cSrcweir ObjectType eParentObjectType = ObjectIdentifier::getObjectType( aParentParticel ); 123cdf0e10cSrcweir eObjectType = eParentObjectType; 124cdf0e10cSrcweir if( OBJECTTYPE_DATA_POINT == eObjectType ) 125cdf0e10cSrcweir nIndex = ObjectIdentifier::getIndexFromParticleOrCID( aParentParticel ); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir if( OBJECTTYPE_DATA_POINT == eObjectType || OBJECTTYPE_DATA_LABEL == eObjectType ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir // Data Point 131cdf0e10cSrcweir fillRangesForDataPoint( xDataSeries, nIndex ); 132cdf0e10cSrcweir return; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir else if( OBJECTTYPE_DATA_ERRORS == eObjectType ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir // select error bar ranges, or data series, if the style is 137cdf0e10cSrcweir // not set to FROM_DATA 138cdf0e10cSrcweir fillRangesForErrorBars( ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ), xDataSeries ); 139cdf0e10cSrcweir return; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir else if( xDataSeries.is() ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir // Data Series 144cdf0e10cSrcweir fillRangesForDataSeries( xDataSeries ); 145cdf0e10cSrcweir return; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir else if( OBJECTTYPE_AXIS == eObjectType ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir // Axis (Categories) 150cdf0e10cSrcweir Reference< chart2::XAxis > xAxis( ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ), uno::UNO_QUERY ); 151cdf0e10cSrcweir if( xAxis.is()) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir fillRangesForCategories( xAxis ); 154cdf0e10cSrcweir return; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir } 157cdf0e10cSrcweir else if( OBJECTTYPE_PAGE == eObjectType 158cdf0e10cSrcweir || OBJECTTYPE_DIAGRAM == eObjectType 159cdf0e10cSrcweir || OBJECTTYPE_DIAGRAM_WALL == eObjectType 160cdf0e10cSrcweir || OBJECTTYPE_DIAGRAM_FLOOR == eObjectType 161cdf0e10cSrcweir ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir // Diagram 164cdf0e10cSrcweir Reference< chart2::XDiagram > xDia( ObjectIdentifier::getDiagramForCID( aCID, xChartModel ) ); 165cdf0e10cSrcweir if( xDia.is()) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir fillRangesForDiagram( xDia ); 168cdf0e10cSrcweir return; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir } 171cdf0e10cSrcweir } 172cdf0e10cSrcweir } 173cdf0e10cSrcweir else if ( rType == ::getCppuType( static_cast< const Reference< drawing::XShape >* >( 0 ) ) ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir // #i12587# support for shapes in chart 176cdf0e10cSrcweir Reference< drawing::XShape > xShape; 177cdf0e10cSrcweir aSelection >>= xShape; 178cdf0e10cSrcweir if ( xShape.is() ) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir return; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir } 183cdf0e10cSrcweir else 184cdf0e10cSrcweir { 185cdf0e10cSrcweir //if nothing is selected select all ranges 186cdf0e10cSrcweir Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY_THROW ); 187cdf0e10cSrcweir fillRangesForDiagram( xChartDoc->getFirstDiagram() ); 188cdf0e10cSrcweir return; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir } 191cdf0e10cSrcweir catch( const uno::Exception & ex ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir } 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir void RangeHighlighter::fillRangesForDiagram( const Reference< chart2::XDiagram > & xDiagram ) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir Sequence< OUString > aSelectedRanges( DataSourceHelper::getUsedDataRanges( xDiagram )); 201cdf0e10cSrcweir m_aSelectedRanges.realloc( aSelectedRanges.getLength()); 202cdf0e10cSrcweir // @todo: merge ranges 203cdf0e10cSrcweir for( sal_Int32 i=0; i<aSelectedRanges.getLength(); ++i ) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir m_aSelectedRanges[i].RangeRepresentation = aSelectedRanges[i]; 206cdf0e10cSrcweir m_aSelectedRanges[i].Index = -1; 207cdf0e10cSrcweir m_aSelectedRanges[i].PreferredColor = PREFERED_DEFAULT_COLOR; 208cdf0e10cSrcweir m_aSelectedRanges[i].AllowMerginigWithOtherRanges = sal_True; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir } 211cdf0e10cSrcweir 212cdf0e10cSrcweir void RangeHighlighter::fillRangesForDataSeries( const uno::Reference< chart2::XDataSeries > & xSeries ) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir sal_Int32 nPreferredColor = PREFERED_DEFAULT_COLOR; 215cdf0e10cSrcweir Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY ); 216cdf0e10cSrcweir if( xSource.is()) 217cdf0e10cSrcweir lcl_fillRanges( m_aSelectedRanges, 218cdf0e10cSrcweir ::chart::DataSourceHelper::getRangesFromDataSource( xSource ), 219cdf0e10cSrcweir nPreferredColor ); 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir void RangeHighlighter::fillRangesForErrorBars( 223cdf0e10cSrcweir const uno::Reference< beans::XPropertySet > & xErrorBar, 224cdf0e10cSrcweir const uno::Reference< chart2::XDataSeries > & xSeries ) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir // only show error bar ranges, if the style is set to FROM_DATA 227cdf0e10cSrcweir bool bUsesRangesAsErrorBars = false; 228cdf0e10cSrcweir try 229cdf0e10cSrcweir { 230cdf0e10cSrcweir sal_Int32 nStyle = ::com::sun::star::chart::ErrorBarStyle::NONE; 231cdf0e10cSrcweir bUsesRangesAsErrorBars = 232cdf0e10cSrcweir ( xErrorBar.is() && 233cdf0e10cSrcweir (xErrorBar->getPropertyValue( C2U("ErrorBarStyle")) >>= nStyle) && 234cdf0e10cSrcweir nStyle == ::com::sun::star::chart::ErrorBarStyle::FROM_DATA ); 235cdf0e10cSrcweir } 236cdf0e10cSrcweir catch( const uno::Exception & ex ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir if( bUsesRangesAsErrorBars ) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir sal_Int32 nPreferredColor = PREFERED_DEFAULT_COLOR; 244cdf0e10cSrcweir Reference< chart2::data::XDataSource > xSource( xErrorBar, uno::UNO_QUERY ); 245cdf0e10cSrcweir if( xSource.is()) 246cdf0e10cSrcweir lcl_fillRanges( m_aSelectedRanges, 247cdf0e10cSrcweir ::chart::DataSourceHelper::getRangesFromDataSource( xSource ), 248cdf0e10cSrcweir nPreferredColor ); 249cdf0e10cSrcweir } 250cdf0e10cSrcweir else 251cdf0e10cSrcweir { 252cdf0e10cSrcweir fillRangesForDataSeries( xSeries ); 253cdf0e10cSrcweir } 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir void RangeHighlighter::fillRangesForCategories( const Reference< chart2::XAxis > & xAxis ) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir if( ! xAxis.is()) 259cdf0e10cSrcweir return; 260cdf0e10cSrcweir chart2::ScaleData aData( xAxis->getScaleData()); 261cdf0e10cSrcweir lcl_fillRanges( m_aSelectedRanges, 262cdf0e10cSrcweir DataSourceHelper::getRangesFromLabeledDataSequence( aData.Categories )); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir void RangeHighlighter::fillRangesForDataPoint( const Reference< uno::XInterface > & xDataSeries, sal_Int32 nIndex ) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir sal_Int32 nPreferredColor = PREFERED_DEFAULT_COLOR; 268cdf0e10cSrcweir if( xDataSeries.is()) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir Reference< chart2::data::XDataSource > xSource( xDataSeries, uno::UNO_QUERY ); 271cdf0e10cSrcweir if( xSource.is() ) 272cdf0e10cSrcweir { 273cdf0e10cSrcweir ::std::vector< chart2::data::HighlightedRange > aHilightedRanges; 274cdf0e10cSrcweir Sequence< Reference< chart2::data::XLabeledDataSequence > > aLSeqSeq( xSource->getDataSequences()); 275cdf0e10cSrcweir for( sal_Int32 i=0; i<aLSeqSeq.getLength(); ++i ) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xLabel( aLSeqSeq[i]->getLabel()); 278cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xValues( aLSeqSeq[i]->getValues()); 279cdf0e10cSrcweir 280cdf0e10cSrcweir if( xLabel.is()) 281cdf0e10cSrcweir aHilightedRanges.push_back( 282cdf0e10cSrcweir chart2::data::HighlightedRange( 283cdf0e10cSrcweir xLabel->getSourceRangeRepresentation(), 284cdf0e10cSrcweir -1, 285cdf0e10cSrcweir nPreferredColor, 286cdf0e10cSrcweir sal_False )); 287cdf0e10cSrcweir 288cdf0e10cSrcweir sal_Int32 nUnhiddenIndex = DataSeriesHelper::translateIndexFromHiddenToFullSequence( nIndex, xValues, !m_bIncludeHiddenCells ); 289cdf0e10cSrcweir if( xValues.is()) 290cdf0e10cSrcweir aHilightedRanges.push_back( 291cdf0e10cSrcweir chart2::data::HighlightedRange( 292cdf0e10cSrcweir xValues->getSourceRangeRepresentation(), 293cdf0e10cSrcweir nUnhiddenIndex, 294cdf0e10cSrcweir nPreferredColor, 295cdf0e10cSrcweir sal_False )); 296cdf0e10cSrcweir } 297cdf0e10cSrcweir m_aSelectedRanges = ContainerHelper::ContainerToSequence( aHilightedRanges ); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir } 300cdf0e10cSrcweir } 301cdf0e10cSrcweir 302cdf0e10cSrcweir void SAL_CALL RangeHighlighter::addSelectionChangeListener( const Reference< view::XSelectionChangeListener >& xListener ) 303cdf0e10cSrcweir throw (uno::RuntimeException) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir if(!xListener.is()) 306cdf0e10cSrcweir return; 307cdf0e10cSrcweir 308cdf0e10cSrcweir if( m_nAddedListenerCount == 0 ) 309cdf0e10cSrcweir startListening(); 310cdf0e10cSrcweir rBHelper.addListener( ::getCppuType( & xListener ), xListener); 311cdf0e10cSrcweir ++m_nAddedListenerCount; 312cdf0e10cSrcweir 313cdf0e10cSrcweir //bring the new listener up to the current state 314cdf0e10cSrcweir lang::EventObject aEvent( static_cast< lang::XComponent* >( this ) ); 315cdf0e10cSrcweir xListener->selectionChanged( aEvent ); 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir void SAL_CALL RangeHighlighter::removeSelectionChangeListener( const Reference< view::XSelectionChangeListener >& xListener ) 319cdf0e10cSrcweir throw (uno::RuntimeException) 320cdf0e10cSrcweir { 321cdf0e10cSrcweir rBHelper.removeListener( ::getCppuType( & xListener ), xListener ); 322cdf0e10cSrcweir --m_nAddedListenerCount; 323cdf0e10cSrcweir if( m_nAddedListenerCount == 0 ) 324cdf0e10cSrcweir stopListening(); 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir // ____ XSelectionChangeListener ____ 328cdf0e10cSrcweir void SAL_CALL RangeHighlighter::selectionChanged( const lang::EventObject& /*aEvent*/ ) 329cdf0e10cSrcweir throw (uno::RuntimeException) 330cdf0e10cSrcweir { 331cdf0e10cSrcweir determineRanges(); 332cdf0e10cSrcweir 333cdf0e10cSrcweir // determine ranges of selected view objects 334cdf0e10cSrcweir // if changed, fire an event 335cdf0e10cSrcweir fireSelectionEvent(); 336cdf0e10cSrcweir } 337cdf0e10cSrcweir 338cdf0e10cSrcweir void RangeHighlighter::fireSelectionEvent() 339cdf0e10cSrcweir { 340cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* pIC = rBHelper.getContainer( 341cdf0e10cSrcweir ::getCppuType((const uno::Reference< view::XSelectionChangeListener >*)0) ); 342cdf0e10cSrcweir if( pIC ) 343cdf0e10cSrcweir { 344cdf0e10cSrcweir lang::EventObject aEvent( static_cast< lang::XComponent* >( this ) ); 345cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper aIt( *pIC ); 346cdf0e10cSrcweir while( aIt.hasMoreElements() ) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir uno::Reference< view::XSelectionChangeListener > xListener( aIt.next(), uno::UNO_QUERY ); 349cdf0e10cSrcweir if( xListener.is() ) 350cdf0e10cSrcweir xListener->selectionChanged( aEvent ); 351cdf0e10cSrcweir } 352cdf0e10cSrcweir } 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir void SAL_CALL RangeHighlighter::disposing( const lang::EventObject& Source ) 356cdf0e10cSrcweir throw (uno::RuntimeException) 357cdf0e10cSrcweir { 358cdf0e10cSrcweir if( Source.Source == m_xSelectionSupplier ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir m_xSelectionSupplier.clear(); 361cdf0e10cSrcweir m_aSelectedRanges.realloc( 0 ); 362cdf0e10cSrcweir fireSelectionEvent(); 363cdf0e10cSrcweir } 364cdf0e10cSrcweir } 365cdf0e10cSrcweir 366cdf0e10cSrcweir void RangeHighlighter::startListening() 367cdf0e10cSrcweir { 368cdf0e10cSrcweir if( m_xSelectionSupplier.is()) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir if( ! m_xListener.is()) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir m_xListener.set( new WeakSelectionChangeListenerAdapter( this )); 373cdf0e10cSrcweir determineRanges(); 374cdf0e10cSrcweir } 375cdf0e10cSrcweir m_xSelectionSupplier->addSelectionChangeListener( m_xListener ); 376cdf0e10cSrcweir } 377cdf0e10cSrcweir } 378cdf0e10cSrcweir 379cdf0e10cSrcweir void RangeHighlighter::stopListening() 380cdf0e10cSrcweir { 381cdf0e10cSrcweir if( m_xSelectionSupplier.is() && m_xListener.is()) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir m_xSelectionSupplier->removeSelectionChangeListener( m_xListener ); 384cdf0e10cSrcweir m_xListener.clear(); 385cdf0e10cSrcweir } 386cdf0e10cSrcweir } 387cdf0e10cSrcweir 388cdf0e10cSrcweir 389cdf0e10cSrcweir // ____ WeakComponentImplHelperBase ____ 390cdf0e10cSrcweir // is called when dispose() is called at this component 391cdf0e10cSrcweir void SAL_CALL RangeHighlighter::disposing() 392cdf0e10cSrcweir { 393cdf0e10cSrcweir // @todo: remove listener. Currently the controller shows an assertion 394cdf0e10cSrcweir // because it is already disposed 395cdf0e10cSrcweir // stopListening(); 396cdf0e10cSrcweir m_xListener.clear(); 397cdf0e10cSrcweir m_xSelectionSupplier.clear(); 398cdf0e10cSrcweir m_nAddedListenerCount = 0; 399cdf0e10cSrcweir m_aSelectedRanges.realloc( 0 ); 400cdf0e10cSrcweir } 401cdf0e10cSrcweir 402cdf0e10cSrcweir } // namespace chart 403