diff -u -r ./old/sc/source/ui/vba/vbaeventshelper.cxx ./new/sc/source/ui/vba/vbaeventshelper.cxx --- ./old/sc/source/ui/vba/vbaeventshelper.cxx 2009-12-26 11:03:32.000000000 +0800 +++ ./new/sc/source/ui/vba/vbaeventshelper.cxx 2010-01-20 13:17:56.000000000 +0800 @@ -14,7 +14,7 @@ * * GNU Lesser General Public License Version 2.1 * ============================================= - * Copyright 2005 by Sun Microsystems, Inc. + * Copyright 2005, 2010 by Sun Microsystems, Inc. * 901 San Antonio Road, Palo Alto, CA 94303, USA * * This library is free software; you can redistribute it and/or @@ -840,6 +840,26 @@ mbDocDisposed = true; } +// Compares the old selection with the new selection to check if the selection is changed. +// Returns sal_True if selection is not changed, otherwise return sal_False. +sal_Bool ScVbaEventsHelper::compareSelection( uno::Any oldSelection, uno::Any newSelection ) +{ + ScCellRangesBase* pNewCellRanges = NULL; + ScCellRangesBase* pOldCellRanges = NULL; + uno::Reference < lang::XUnoTunnel > xOldTunnel( oldSelection, uno::UNO_QUERY ); + uno::Reference < lang::XUnoTunnel > xNewTunnel( newSelection, uno::UNO_QUERY ); + if ( xOldTunnel.is() && xNewTunnel.is() ) + { + pOldCellRanges = reinterpret_cast( xOldTunnel->getSomething( ScCellRangesBase::getUnoTunnelId() ) ); + pNewCellRanges = reinterpret_cast( xNewTunnel->getSomething( ScCellRangesBase::getUnoTunnelId() ) ); + if ( pNewCellRanges && pOldCellRanges && pNewCellRanges->GetRangeList() == pOldCellRanges->GetRangeList() ) + { + return sal_True; + } + } + return sal_False; +} + sal_Bool SAL_CALL ScVbaEventsHelper::ProcessCompatibleVbaEvent( sal_Int32 nEventId, const uno::Sequence< uno::Any >& aArgs ) throw (uno::RuntimeException) { @@ -931,8 +951,10 @@ case VBAEVENT_WORKSHEET_SELECTIONCHANGE: { nTab = getTabFromArgs( aArgs ); - if( nTab != INVALID_TAB ) + // Check whether the selection is changed. If selection is not changed, then do not fire the SelectionChange event. + if( nTab != INVALID_TAB && !compareSelection( m_curSelection, aArgs[0] ) ) { + m_curSelection = aArgs[0]; processVbaEvent( nEventId, aArgs, nTab ); ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_SHEET_SELECTIONCHANGE, aArgs ); } diff -u -r ./old/sc/source/ui/vba/vbaeventshelper.hxx ./new/sc/source/ui/vba/vbaeventshelper.hxx --- ./old/sc/source/ui/vba/vbaeventshelper.hxx 2009-12-26 11:03:32.000000000 +0800 +++ ./new/sc/source/ui/vba/vbaeventshelper.hxx 2010-01-20 13:18:06.000000000 +0800 @@ -14,7 +14,7 @@ * * GNU Lesser General Public License Version 2.1 * ============================================= - * Copyright 2005 by Sun Microsystems, Inc. + * Copyright 2005, 2010 by Sun Microsystems, Inc. * 901 San Antonio Road, Palo Alto, CA 94303, USA * * This library is free software; you can redistribute it and/or @@ -61,6 +61,7 @@ css::uno::Reference< css::awt::XWindowListener > m_xVbaEventsListener; sal_Bool mbOpened; sal_Bool mbDocDisposed; + css::uno::Any m_curSelection; String getSheetModuleName( SCTAB nTab ); css::uno::Any createWorkSheet( SfxObjectShell* pShell, SCTAB nTab ); @@ -72,6 +73,8 @@ sal_Bool processVbaEvent( const sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs, const SCTAB nTab = INVALID_TAB ); void Initilize(); void stopListening(); + sal_Bool compareSelection( css::uno::Any oldSelection, css::uno::Any newSelection ); + public: //ScVbaEventsHelper( ScDocument* pDocument ):pDoc( pDocument ), mbOpened( sal_False ){}; ScVbaEventsHelper( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext > const& xContext );