From 4eed799a79cffa08a9cae7e8980a0f4673441289 Mon Sep 17 00:00:00 2001 From: Daniel Rentz Date: Wed, 18 Aug 2010 17:20:31 +0200 Subject: mib19: #163305# do not fire sheet activation events, when a sheet gets inserted/deleted etc. and the active sheet just changes its index --- sc/source/ui/inc/tabview.hxx | 9 ++++----- sc/source/ui/unoobj/viewuno.cxx | 7 ++++--- sc/source/ui/vba/vbaeventshelper.cxx | 22 +++++++++++----------- sc/source/ui/view/tabview3.cxx | 4 ++-- sc/source/ui/view/tabview5.cxx | 4 ++-- sc/source/ui/view/tabvwsh5.cxx | 9 +++++---- 6 files changed, 28 insertions(+), 27 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx index a6e99613f2ea..ab21a6161752 100644 --- a/sc/source/ui/inc/tabview.hxx +++ b/sc/source/ui/inc/tabview.hxx @@ -287,7 +287,8 @@ public: BOOL IsMinimized() const { return bMinimized; } - void TabChanged(); + // bSameTabButMoved = true if the same sheet as before is activated, used after moving/copying/inserting/deleting a sheet + void TabChanged( bool bSameTabButMoved = false ); void SetZoom( const Fraction& rNewX, const Fraction& rNewY, BOOL bAll ); SC_DLLPUBLIC void RefreshZoom(); void SetPagebreakMode( BOOL bSet ); @@ -387,10 +388,8 @@ public: void SetNewStartIfMarking(); - //Added by PengYunQuan for Validity Cell Range Picker + // bSameTabButMoved = true if the same sheet as before is activated, used after moving/copying/inserting/deleting a sheet + SC_DLLPUBLIC void SetTabNo( SCTAB nTab, BOOL bNew = FALSE, BOOL bExtendSelection = FALSE, bool bSameTabButMoved = false ); void SelectNextTab( short nDir, BOOL bExtendSelection = FALSE ); void ActivateView( BOOL bActivate, BOOL bFirst ); diff --git a/sc/source/ui/unoobj/viewuno.cxx b/sc/source/ui/unoobj/viewuno.cxx index fd1e655b8ffb..7646e52c030f 100644 --- a/sc/source/ui/unoobj/viewuno.cxx +++ b/sc/source/ui/unoobj/viewuno.cxx @@ -572,7 +572,7 @@ void lcl_CallActivate( ScDocShell* pDocSh, SCTAB nTab, sal_Int32 nEvent ) } } -void ScTabViewObj::SheetChanged() +void ScTabViewObj::SheetChanged( bool bSameTabButMoved ) { if ( !GetViewShell() ) return; @@ -600,9 +600,10 @@ void ScTabViewObj::SheetChanged() } } - // handle sheet events + /* Handle sheet events, but do not trigger event handlers, if the old + active sheet gets re-activated after inserting/deleting/moving a sheet. */ SCTAB nNewTab = pViewData->GetTabNo(); - if ( nNewTab != nPreviousTab ) + if ( !bSameTabButMoved && (nNewTab != nPreviousTab) ) { lcl_CallActivate( pDocSh, nPreviousTab, SC_SHEETEVENT_UNFOCUS ); lcl_CallActivate( pDocSh, nNewTab, SC_SHEETEVENT_FOCUS ); diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx index 45667adf2f2c..f19a2e57e549 100755 --- a/sc/source/ui/vba/vbaeventshelper.cxx +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -470,14 +470,12 @@ bool ScVbaEventsHelper::implEventsEnabled() throw (uno::RuntimeException) bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, const uno::Sequence< uno::Any >& rArgs ) throw (uno::RuntimeException) { - // check preconditions for some events, add more events if needed - bool bExecuteEvent = true; + // framework and Calc fire a few events before 'opened', ignore them + bool bExecuteEvent = mbOpened; + + // special handling for some events switch( rInfo.mnEventId ) { - case WORKBOOK_ACTIVATE: - // while loading, framework fires this before 'opened' event, delay it - bExecuteEvent = mbOpened; - break; case WORKBOOK_OPEN: bExecuteEvent = !mbOpened; if( bExecuteEvent ) @@ -490,15 +488,17 @@ bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, break; case WORKSHEET_SELECTIONCHANGE: // if selection is not changed, then do not fire the event - bExecuteEvent = mbOpened && isSelectionChanged( rArgs, 0 ); + bExecuteEvent = bExecuteEvent && isSelectionChanged( rArgs, 0 ); break; } // add workbook event associated to a sheet event - bool bSheetEvent = false; - rInfo.maUserData >>= bSheetEvent; - if( bSheetEvent && bExecuteEvent ) - rEventQueue.push_back( EventQueueEntry( rInfo.mnEventId + USERDEFINED_START, rArgs ) ); + if( bExecuteEvent ) + { + bool bSheetEvent = false; + if( (rInfo.maUserData >>= bSheetEvent) && bSheetEvent ) + rEventQueue.push_back( EventQueueEntry( rInfo.mnEventId + USERDEFINED_START, rArgs ) ); + } return bExecuteEvent; } diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx index 90bfe0c24e5c..93d1edd7fee5 100644 --- a/sc/source/ui/view/tabview3.cxx +++ b/sc/source/ui/view/tabview3.cxx @@ -1549,7 +1549,7 @@ void ScTabView::SelectNextTab( short nDir, BOOL bExtendSelection ) // SetTabNo - angezeigte Tabelle -void ScTabView::SetTabNo( SCTAB nTab, BOOL bNew, BOOL bExtendSelection ) +void ScTabView::SetTabNo( SCTAB nTab, BOOL bNew, BOOL bExtendSelection, bool bSameTabButMoved ) { if ( !ValidTab(nTab) ) { @@ -1681,7 +1681,7 @@ void ScTabView::SetTabNo( SCTAB nTab, BOOL bNew, BOOL bExtendSelection ) pGridWin[i]->UpdateEditViewPos(); } - TabChanged(); // DrawView + TabChanged( bSameTabButMoved ); // DrawView aViewData.GetViewShell()->WindowChanged(); // falls das aktive Fenster anders ist if ( !bUnoRefDialog ) diff --git a/sc/source/ui/view/tabview5.cxx b/sc/source/ui/view/tabview5.cxx index f0ac3fc42869..f5a4a37784a9 100644 --- a/sc/source/ui/view/tabview5.cxx +++ b/sc/source/ui/view/tabview5.cxx @@ -267,7 +267,7 @@ void ScTabView::DoAddWin( ScGridWindow* pWin ) //================================================================== -void ScTabView::TabChanged() +void ScTabView::TabChanged( bool bSameTabButMoved ) { if (pDrawView) { @@ -339,7 +339,7 @@ void ScTabView::TabChanged() { ScTabViewObj* pImp = ScTabViewObj::getImplementation( xController ); if (pImp) - pImp->SheetChanged(); + pImp->SheetChanged( bSameTabButMoved ); } } } diff --git a/sc/source/ui/view/tabvwsh5.cxx b/sc/source/ui/view/tabvwsh5.cxx index 1a3dd6928a17..12f08ec6d0e2 100644 --- a/sc/source/ui/view/tabvwsh5.cxx +++ b/sc/source/ui/view/tabvwsh5.cxx @@ -249,7 +249,7 @@ void __EXPORT ScTabViewShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint // kann und dann auch die aktive View umgeschaltet werden muss. SCTAB nNewTab = nActiveTab; - BOOL bForce = FALSE; + bool bStayOnActiveTab = true; switch (nId) { case SC_TAB_INSERTED: @@ -260,7 +260,7 @@ void __EXPORT ScTabViewShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint if ( nTab1 < nNewTab ) // vorher geloescht --nNewTab; else if ( nTab1 == nNewTab ) // aktuelle geloescht - bForce = TRUE; + bStayOnActiveTab = false; break; case SC_TAB_MOVED: if ( nNewTab == nTab1 ) // verschobene Tabelle @@ -282,7 +282,7 @@ void __EXPORT ScTabViewShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint break; case SC_TAB_HIDDEN: if ( nTab1 == nNewTab ) // aktuelle ausgeblendet - bForce = TRUE; + bStayOnActiveTab = false; break; } @@ -290,7 +290,8 @@ void __EXPORT ScTabViewShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint if ( nNewTab >= pDoc->GetTableCount() ) nNewTab = pDoc->GetTableCount() - 1; - SetTabNo( nNewTab, bForce ); + BOOL bForce = !bStayOnActiveTab; + SetTabNo( nNewTab, bForce, FALSE, bStayOnActiveTab ); } else if (rHint.ISA(ScIndexHint)) { -- cgit From f43dbd543d60efafd66bb50c5e4e2d0bf6ee0d53 Mon Sep 17 00:00:00 2001 From: Daniel Rentz Date: Mon, 23 Aug 2010 12:08:40 +0200 Subject: #163288# treat Excel number format 'General' as standard format --- sc/source/ui/vba/vbarange.cxx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 455af075306c..d34c0421805f 100755 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -539,19 +539,22 @@ public: { uno::Reference< beans::XPropertySet > xNumberProps = getNumberProps(); sal_Int16 nType = ::comphelper::getINT16( - xNumberProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Type" ) ) ); + xNumberProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ) ) ) ); return nType; } - bool setNumberFormat( const rtl::OUString& rFormat ) + bool setNumberFormat( const rtl::OUString& rFormat ) { - lang::Locale aLocale; - uno::Reference< beans::XPropertySet > xNumProps = getNumberProps(); - xNumProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Locale" ) ) >>= aLocale; - sal_Int32 nNewIndex = mxFormats->queryKey(rFormat, aLocale, false ); - if ( nNewIndex == -1 ) // format not defined + // #163288# treat "General" as "Standard" format + sal_Int32 nNewIndex = 0; + if( !rFormat.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "General" ) ) ) { - nNewIndex = mxFormats->addNew( rFormat, aLocale ); + lang::Locale aLocale; + uno::Reference< beans::XPropertySet > xNumProps = getNumberProps(); + xNumProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Locale" ) ) ) >>= aLocale; + nNewIndex = mxFormats->queryKey( rFormat, aLocale, false ); + if ( nNewIndex == -1 ) // format not defined + nNewIndex = mxFormats->addNew( rFormat, aLocale ); } mxRangeProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberFormat") ), uno::makeAny( nNewIndex ) ); return true; @@ -561,7 +564,7 @@ public: { uno::Reference< beans::XPropertySet > xNumberProps = getNumberProps(); lang::Locale aLocale; - xNumberProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Locale" ) ) >>= aLocale; + xNumberProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Locale" ) ) ) >>= aLocale; uno::Reference xTypes( mxFormats, uno::UNO_QUERY ); if ( xTypes.is() ) { -- cgit From c99b24c76c886ddaa93e290412c7674807c23405 Mon Sep 17 00:00:00 2001 From: Daniel Rentz Date: Mon, 23 Aug 2010 13:53:47 +0200 Subject: mib19: improved event handling: do not supreppress global events, when Application.EnableEvents symbol set to false --- sc/source/ui/vba/vbaeventshelper.cxx | 50 +++++++++++++++++------------------- sc/source/ui/vba/vbaeventshelper.hxx | 1 - 2 files changed, 24 insertions(+), 27 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx index f19a2e57e549..99ccbeaaa822 100755 --- a/sc/source/ui/vba/vbaeventshelper.cxx +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -441,35 +441,13 @@ void SAL_CALL ScVbaEventsHelper::disposing( const lang::EventObject& rSource ) t // protected ------------------------------------------------------------------ -bool ScVbaEventsHelper::implEventsEnabled() throw (uno::RuntimeException) +bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, + const EventHandlerInfo& rInfo, const uno::Sequence< uno::Any >& rArgs ) throw (uno::RuntimeException) { // document and document shell are needed during event processing - if( !mpDocShell || !mpDoc ) + if( !mpShell || !mpDoc ) throw uno::RuntimeException(); - // get Application object and check if events are enabled (this is an Excel-only attribute) - uno::Reference< excel::XApplication > xApplication( mxApplication.get(), uno::UNO_QUERY ); - if( !xApplication.is() && mpShell ) - { - uno::Any aVBAGlobals; - mpShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aVBAGlobals ); - uno::Reference< XHelperInterface > xHelperInterface( aVBAGlobals, uno::UNO_QUERY ); - if( xHelperInterface.is() ) - { - xApplication.set( xHelperInterface->Application(), uno::UNO_QUERY ); - mxApplication = xApplication; - } - } - if( !xApplication.is() ) - throw uno::RuntimeException(); - - // return whether event processing is enabled - return xApplication->getEnableEvents(); -} - -bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, - const EventHandlerInfo& rInfo, const uno::Sequence< uno::Any >& rArgs ) throw (uno::RuntimeException) -{ // framework and Calc fire a few events before 'opened', ignore them bool bExecuteEvent = mbOpened; @@ -492,12 +470,32 @@ bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, break; } - // add workbook event associated to a sheet event if( bExecuteEvent ) { + // add workbook event associated to a sheet event bool bSheetEvent = false; if( (rInfo.maUserData >>= bSheetEvent) && bSheetEvent ) rEventQueue.push_back( EventQueueEntry( rInfo.mnEventId + USERDEFINED_START, rArgs ) ); + + /* For document events: get Application object and check if events are + enabled via EnableEvents symbol (this is an Excel-only attribute). + Check this again for every event, as the event handler may change + the state of the EnableEvents symbol. Global events such as + AUTO_OPEN and AUTO_CLOSE are always enabled. */ + if( rInfo.meType == EVENTHANDLER_DOCUMENT ) + { + // reference to application is held weakly, get application on first try + uno::Reference< excel::XApplication > xApplication( mxApplication.get(), uno::UNO_QUERY ); + if( !xApplication.is() ) + { + uno::Any aVBAGlobals; + mpShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aVBAGlobals ); + uno::Reference< XHelperInterface > xHelperInterface( aVBAGlobals, uno::UNO_QUERY_THROW ); + xApplication.set( xHelperInterface->Application(), uno::UNO_QUERY_THROW ); + mxApplication = xApplication; + } + bExecuteEvent = xApplication->getEnableEvents(); + } } return bExecuteEvent; diff --git a/sc/source/ui/vba/vbaeventshelper.hxx b/sc/source/ui/vba/vbaeventshelper.hxx index a77f5128b3e9..eaac96117d32 100755 --- a/sc/source/ui/vba/vbaeventshelper.hxx +++ b/sc/source/ui/vba/vbaeventshelper.hxx @@ -51,7 +51,6 @@ public: virtual void SAL_CALL disposing( const css::lang::EventObject& rSource ) throw (css::uno::RuntimeException); protected: - virtual bool implEventsEnabled() throw (css::uno::RuntimeException); virtual bool implPrepareEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::uno::RuntimeException); virtual css::uno::Sequence< css::uno::Any > implBuildArgumentList( const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException); virtual void implPostProcessEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, bool bSuccess, bool bCancel ) throw (css::uno::RuntimeException); -- cgit From 9d3ae8930790c4a9afc10995fd9a2dd5a4b2b4ba Mon Sep 17 00:00:00 2001 From: Daniel Rentz Date: Tue, 24 Aug 2010 16:59:15 +0200 Subject: mib19: enable document event handling in workbooks created via VBA symbol Workbooks.Add --- sc/source/ui/docshell/docsh.cxx | 9 +-------- sc/source/ui/unoobj/servuno.cxx | 8 ++++++-- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index d5d7f6e09292..9e98d7430d96 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -72,7 +72,6 @@ #include #include #include -#include #include "scabstdlg.hxx" //CHINA001 #include @@ -625,15 +624,9 @@ void __EXPORT ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) { uno::Reference< frame::XModel > xModel( GetModel(), uno::UNO_SET_THROW ); - // create VBAGlobals object if not yet done (this also creates the "ThisExcelDoc" symbol) + // create VBAGlobals object if not yet done (this also creates the "ThisExcelDoc" symbol and the event processor) uno::Reference< lang::XMultiServiceFactory > xFactory( xModel, uno::UNO_QUERY_THROW ); xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAGlobals" ) ) ); - - // create the VBA document event processor - uno::Sequence< uno::Any > aArgs( 1 ); - aArgs[ 0 ] <<= xModel; - xVbaEvents.set( ooo::vba::createVBAUnoAPIServiceWithArgs( this, "com.sun.star.script.vba.VBASpreadsheetEventProcessor" , aArgs ), uno::UNO_QUERY ); - aDocument.SetVbaEventProcessor( xVbaEvents ); } catch( uno::Exception& ) { diff --git a/sc/source/ui/unoobj/servuno.cxx b/sc/source/ui/unoobj/servuno.cxx index a173e6d1e051..0a1f86afd7d1 100644 --- a/sc/source/ui/unoobj/servuno.cxx +++ b/sc/source/ui/unoobj/servuno.cxx @@ -28,8 +28,6 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sc.hxx" - - #include #include #include @@ -61,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -573,6 +572,11 @@ uno::Reference ScServiceProvider::MakeInstance( BasicManager* pAppMgr = SFX_APP()->GetBasicManager(); if ( pAppMgr ) pAppMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[ 0 ] ); + + // create the VBA document event processor + uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( + ::ooo::vba::createVBAUnoAPIServiceWithArgs( pDocShell, "com.sun.star.script.vba.VBASpreadsheetEventProcessor", aArgs ), uno::UNO_QUERY ); + pDocShell->GetDocument()->SetVbaEventProcessor( xVbaEvents ); } } break; -- cgit From 997221829f958e2ca08e9b8d57292f380317e808 Mon Sep 17 00:00:00 2001 From: Daniel Rentz Date: Wed, 25 Aug 2010 13:43:42 +0200 Subject: mib19: #163419# do not throw exceptions into Application core --- sc/source/ui/vba/vbaeventshelper.cxx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx index 99ccbeaaa822..7b0400c59b76 100755 --- a/sc/source/ui/vba/vbaeventshelper.cxx +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -90,7 +90,6 @@ private: uno::Reference< awt::XWindow > getContainerWindow(); bool isMouseReleased(); DECL_LINK( fireResizeMacro, void* ); - void processWindowResizeMacro(); private: ::osl::Mutex maMutex; @@ -271,6 +270,8 @@ void SAL_CALL ScVbaEventsListener::borderWidthsChanged( const uno::Reference< un void SAL_CALL ScVbaEventsListener::changesOccurred( const util::ChangesEvent& aEvent ) throw (uno::RuntimeException) { + if( !mrVbaEvents.hasVbaEventHandler( WORKSHEET_CHANGE, aArgs ) ) + sal_Int32 nCount = aEvent.Changes.getLength(); if( nCount == 0 ) return; @@ -362,19 +363,18 @@ bool ScVbaEventsListener::isMouseReleased() IMPL_LINK( ScVbaEventsListener, fireResizeMacro, void*, EMPTYARG ) { - if( !mbDisposed && isMouseReleased() ) - processWindowResizeMacro(); + if( !mbDisposed && isMouseReleased() ) try + { + mrVbaEvents.processVbaEvent( WORKBOOK_WINDOWRESIZE, uno::Sequence< uno::Any >() ); + } + catch( uno::Exception& ) + { + // #163419# do not throw exceptions into application core + } release(); return 0; } -void ScVbaEventsListener::processWindowResizeMacro() -{ - OSL_TRACE( "**** Attempt to FIRE MACRO **** " ); - if( !mbDisposed ) - mrVbaEvents.processVbaEvent( WORKBOOK_WINDOWRESIZE, uno::Sequence< uno::Any >() ); -} - // ============================================================================ ScVbaEventsHelper::ScVbaEventsHelper( const uno::Sequence< uno::Any >& rArgs, const uno::Reference< uno::XComponentContext >& xContext ) : -- cgit From cec16f1b7a3c5e7327b41c8b4a5386628b339f0d Mon Sep 17 00:00:00 2001 From: Daniel Rentz Date: Wed, 25 Aug 2010 13:48:27 +0200 Subject: mib19: #163419# corrected wrong commit --- sc/source/ui/vba/vbaeventshelper.cxx | 2 -- 1 file changed, 2 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx index 7b0400c59b76..996bf52e0794 100755 --- a/sc/source/ui/vba/vbaeventshelper.cxx +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -270,8 +270,6 @@ void SAL_CALL ScVbaEventsListener::borderWidthsChanged( const uno::Reference< un void SAL_CALL ScVbaEventsListener::changesOccurred( const util::ChangesEvent& aEvent ) throw (uno::RuntimeException) { - if( !mrVbaEvents.hasVbaEventHandler( WORKSHEET_CHANGE, aArgs ) ) - sal_Int32 nCount = aEvent.Changes.getLength(); if( nCount == 0 ) return; -- cgit From 7e8aec45e5b2313a682fcec37e47e2f6ee8a2a47 Mon Sep 17 00:00:00 2001 From: Daniel Rentz Date: Thu, 26 Aug 2010 14:15:19 +0200 Subject: mib19: #163428# VBA symbol Worksheet.Visible supports xlSheetVeryHidden now --- sc/source/ui/vba/vbaworksheet.cxx | 43 +++++++++++++++++++++++++++------------ sc/source/ui/vba/vbaworksheet.hxx | 5 +++-- 2 files changed, 33 insertions(+), 15 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx index 6ee6fa1f6b19..b2421727f109 100644 --- a/sc/source/ui/vba/vbaworksheet.cxx +++ b/sc/source/ui/vba/vbaworksheet.cxx @@ -61,6 +61,7 @@ #include #include #include +#include #include #include @@ -179,18 +180,18 @@ openNewDoc(rtl::OUString aSheetName ) return xModel; } -ScVbaWorksheet::ScVbaWorksheet( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : WorksheetImpl_BASE( xParent, xContext ) +ScVbaWorksheet::ScVbaWorksheet( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : WorksheetImpl_BASE( xParent, xContext ), mbVeryHidden( false ) { } ScVbaWorksheet::ScVbaWorksheet(const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XSpreadsheet >& xSheet, - const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) : WorksheetImpl_BASE( xParent, xContext ), mxSheet( xSheet ), mxModel(xModel) + const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) : WorksheetImpl_BASE( xParent, xContext ), mxSheet( xSheet ), mxModel(xModel), mbVeryHidden( false ) { } ScVbaWorksheet::ScVbaWorksheet( uno::Sequence< uno::Any> const & args, - uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) : WorksheetImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), mxModel( getXSomethingFromArgs< frame::XModel >( args, 1 ) ) + uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) : WorksheetImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), mxModel( getXSomethingFromArgs< frame::XModel >( args, 1 ) ), mbVeryHidden( false ) { if ( args.getLength() < 2 ) throw lang::IllegalArgumentException(); @@ -221,24 +222,40 @@ ScVbaWorksheet::setName(const ::rtl::OUString &rName ) throw (uno::RuntimeExcept xNamed->setName( rName ); } -sal_Bool +sal_Int32 ScVbaWorksheet::getVisible() throw (uno::RuntimeException) { uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW ); - uno::Any aValue = xProps->getPropertyValue - (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) ) ); - sal_Bool bRet = false; - aValue >>= bRet; - return bRet; + bool bVisible = false; + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) ) ) >>= bVisible; + using namespace ::ooo::vba::excel::XlSheetVisibility; + return bVisible ? xlSheetVisible : (mbVeryHidden ? xlSheetVeryHidden : xlSheetHidden); } void -ScVbaWorksheet::setVisible( sal_Bool bVisible ) throw (uno::RuntimeException) +ScVbaWorksheet::setVisible( sal_Int32 nVisible ) throw (uno::RuntimeException) { + using namespace ::ooo::vba::excel::XlSheetVisibility; + bool bVisible = true; + switch( nVisible ) + { + case xlSheetVisible: case 1: // Excel accepts -1 and 1 for visible sheets + bVisible = true; + mbVeryHidden = false; + break; + case xlSheetHidden: + bVisible = false; + mbVeryHidden = false; + break; + case xlSheetVeryHidden: + bVisible = false; + mbVeryHidden = true; + break; + default: + throw uno::RuntimeException(); + } uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW ); - uno::Any aValue( bVisible ); - xProps->setPropertyValue - (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) ), aValue); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) ), uno::Any( bVisible ) ); } sal_Int16 diff --git a/sc/source/ui/vba/vbaworksheet.hxx b/sc/source/ui/vba/vbaworksheet.hxx index 78bcc2503a49..ff5850b7c445 100644 --- a/sc/source/ui/vba/vbaworksheet.hxx +++ b/sc/source/ui/vba/vbaworksheet.hxx @@ -62,6 +62,7 @@ class ScVbaWorksheet : public WorksheetImpl_BASE css::uno::Reference< ov::excel::XChartObjects > mxCharts; css::uno::Reference< ov::excel::XHyperlinks > mxHlinks; ::rtl::Reference< ScVbaSheetObjectsBase > mxButtons; + bool mbVeryHidden; css::uno::Reference< ov::excel::XWorksheet > getSheetAtOffset(SCTAB offset) throw (css::uno::RuntimeException); css::uno::Reference< ov::excel::XRange > getSheetRange() throw (css::uno::RuntimeException); @@ -91,8 +92,8 @@ public: // Attributes virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); virtual void SAL_CALL setName( const ::rtl::OUString &rName ) throw (css::uno::RuntimeException); - virtual sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); - virtual void SAL_CALL setVisible( sal_Bool bVisible ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Int32 nVisible ) throw (css::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL getStandardWidth() throw (css::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL getStandardHeight() throw (css::uno::RuntimeException); virtual ::sal_Bool SAL_CALL getProtectionMode() throw (css::uno::RuntimeException); -- cgit From 02ced0d8f545a00a610ae461d925e7851e9baef0 Mon Sep 17 00:00:00 2001 From: "Daniel Rentz [dr]" Date: Wed, 1 Sep 2010 10:26:59 +0200 Subject: mib19: #163498# correct parent for sheet-local defined names --- sc/source/ui/vba/vbanames.cxx | 5 +++-- sc/source/ui/vba/vbaworkbook.cxx | 14 ++++++-------- sc/source/ui/vba/vbaworksheet.cxx | 13 +++++++++++-- 3 files changed, 20 insertions(+), 12 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbanames.cxx b/sc/source/ui/vba/vbanames.cxx index 9fd22bf89f7a..1386bec7fa70 100644 --- a/sc/source/ui/vba/vbanames.cxx +++ b/sc/source/ui/vba/vbanames.cxx @@ -100,7 +100,6 @@ ScVbaNames::Add( const css::uno::Any& Name , const css::uno::Any& RefersToR1C1, const css::uno::Any& RefersToR1C1Local ) throw (css::uno::RuntimeException) { - rtl::OUString sName; uno::Reference< excel::XRange > xRange; if ( Name.hasValue() ) @@ -158,6 +157,8 @@ ScVbaNames::Add( const css::uno::Any& Name , if ( mxNames->hasByName( sName ) ) mxNames->removeByName(sName); mxNames->addNewByName( sName , rtl::OUString(sTmp) , aCellAddr , (sal_Int32)nType); + uno::Reference< sheet::XNamedRange > xName( mxNames->getByName( sName ), uno::UNO_QUERY_THROW ); + return uno::Any( uno::Reference< excel::XName >( new ScVbaName( getParent(), mxContext, xName, mxNames, mxModel ) ) ); } } return css::uno::Any(); @@ -174,7 +175,7 @@ uno::Reference< container::XEnumeration > ScVbaNames::createEnumeration() throw (uno::RuntimeException) { uno::Reference< container::XEnumerationAccess > xEnumAccess( mxNames, uno::UNO_QUERY_THROW ); - return new NamesEnumeration( this, mxContext, xEnumAccess->createEnumeration(), mxModel , mxNames ); + return new NamesEnumeration( getParent(), mxContext, xEnumAccess->createEnumeration(), mxModel , mxNames ); } uno::Any diff --git a/sc/source/ui/vba/vbaworkbook.cxx b/sc/source/ui/vba/vbaworkbook.cxx index 28469c4685a2..1e2acd6252b8 100644 --- a/sc/source/ui/vba/vbaworkbook.cxx +++ b/sc/source/ui/vba/vbaworkbook.cxx @@ -300,7 +300,7 @@ ScVbaWorkbook::SaveCopyAs( const rtl::OUString& sFileName ) throw ( uno::Runtime } css::uno::Any SAL_CALL -ScVbaWorkbook::Styles( const::uno::Any& Item ) throw (uno::RuntimeException) +ScVbaWorkbook::Styles( const uno::Any& Item ) throw (uno::RuntimeException) { // quick look and Styles object doesn't seem to have a valid parent // or a least the object browser just shows an object that has no @@ -313,18 +313,16 @@ ScVbaWorkbook::Styles( const::uno::Any& Item ) throw (uno::RuntimeException) // Amelia Wang uno::Any SAL_CALL -ScVbaWorkbook::Names( const css::uno::Any& aIndex ) throw (uno::RuntimeException) +ScVbaWorkbook::Names( const uno::Any& aIndex ) throw (uno::RuntimeException) { - uno::Reference< frame::XModel > xModel( getModel() ); + uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW ); uno::Reference< beans::XPropertySet > xProps( xModel, uno::UNO_QUERY_THROW ); uno::Reference< sheet::XNamedRanges > xNamedRanges( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NamedRanges") ) ), uno::UNO_QUERY_THROW ); - uno::Reference< XCollection > xNames( new ScVbaNames( this , mxContext , xNamedRanges , xModel )); - if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID ) - { + uno::Reference< XCollection > xNames( new ScVbaNames( this, mxContext, xNamedRanges, xModel ) ); + if ( aIndex.hasValue() ) + return uno::Any( xNames->Item( aIndex, uno::Any() ) ); return uno::Any( xNames ); } - return uno::Any( xNames->Item( aIndex, uno::Any() ) ); -} rtl::OUString& ScVbaWorkbook::getServiceImplName() diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx index b2421727f109..1f31cb7e19ce 100644 --- a/sc/source/ui/vba/vbaworksheet.cxx +++ b/sc/source/ui/vba/vbaworksheet.cxx @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -95,6 +96,7 @@ #include "vbaworksheets.hxx" #include "vbahyperlinks.hxx" #include "vbasheetobjects.hxx" +#include "vbanames.hxx" #define STANDARDWIDTH 2267 #define STANDARDHEIGHT 427 @@ -733,8 +735,15 @@ ScVbaWorksheet::Hyperlinks( const uno::Any& aIndex ) throw (uno::RuntimeExceptio uno::Any SAL_CALL ScVbaWorksheet::Names( const css::uno::Any& aIndex ) throw (uno::RuntimeException) { - uno::Reference< excel::XWorkbook > xWorkbook( getParent(), uno::UNO_QUERY_THROW ); - return xWorkbook->Names( aIndex ); + // fake sheet-local names by returning all global names + // #163498# initialize Names object with correct parent (this worksheet) + // TODO: real sheet-local names... + uno::Reference< beans::XPropertySet > xProps( mxModel, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XNamedRanges > xNamedRanges( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NamedRanges") ) ), uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xNames( new ScVbaNames( this, mxContext, xNamedRanges, mxModel ) ); + if ( aIndex.hasValue() ) + return uno::Any( xNames->Item( aIndex, uno::Any() ) ); + return uno::Any( xNames ); } uno::Any SAL_CALL -- cgit From 70f55868b448b1e04130fac5552b1476bb564c80 Mon Sep 17 00:00:00 2001 From: "Daniel Rentz [dr]" Date: Thu, 2 Sep 2010 16:24:32 +0200 Subject: mib19: #163525# handle missing codenames in XLS files --- sc/source/ui/docshell/docfunc.cxx | 3 +-- sc/source/ui/unoobj/cellsuno.cxx | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 36b6641d94a6..27112d8c62c2 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -2650,8 +2650,7 @@ void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, String& sModuleName, String uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY ); if ( xVBAModuleInfo.is() ) { - String sCodeName( genModuleName ); - rDoc.SetCodeName( nTab, sCodeName ); + rDoc.SetCodeName( nTab, genModuleName ); script::ModuleInfo sModuleInfo = lcl_InitModuleInfo( rDocSh, genModuleName ); xVBAModuleInfo->insertModuleInfo( genModuleName, sModuleInfo ); xLib->insertByName( genModuleName, aSourceAny ); diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index dea7cc056756..ffef1a914a29 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -8482,8 +8482,7 @@ void ScTableSheetObj::SetOnePropertyValue( const SfxItemPropertySimpleEntry* pEn rtl::OUString aCodeName; if ( pDocSh && ( aValue >>= aCodeName ) ) { - String sNewName( aCodeName ); - pDocSh->GetDocument()->SetCodeName( GetTab_Impl(), sNewName ); + pDocSh->GetDocument()->SetCodeName( GetTab_Impl(), aCodeName ); } } else -- cgit From e0e1dac321cd029d51f211979b43c039b1a2ddfa Mon Sep 17 00:00:00 2001 From: Niklas Nebel Date: Tue, 7 Sep 2010 15:52:13 +0200 Subject: mib19: #163561# use mode SC_SIZE_DIRECT for SetWidthOrHeight --- sc/source/ui/vba/vbarange.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index d34c0421805f..230af4f5d5e3 100755 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -3740,7 +3740,8 @@ ScVbaRange::setColumnWidth( const uno::Any& _columnwidth ) throw (uno::RuntimeEx SCCOLROW nColArr[2]; nColArr[0] = thisAddress.StartColumn; nColArr[1] = thisAddress.EndColumn; - aFunc.SetWidthOrHeight( TRUE, 1, nColArr, thisAddress.Sheet, SC_SIZE_ORIGINAL, + // #163561# use mode SC_SIZE_DIRECT: hide for width 0, show for other values + aFunc.SetWidthOrHeight( TRUE, 1, nColArr, thisAddress.Sheet, SC_SIZE_DIRECT, nTwips, TRUE, TRUE ); } @@ -3904,7 +3905,8 @@ ScVbaRange::setRowHeight( const uno::Any& _rowheight) throw (uno::RuntimeExcepti SCCOLROW nRowArr[2]; nRowArr[0] = thisAddress.StartRow; nRowArr[1] = thisAddress.EndRow; - aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, thisAddress.Sheet, SC_SIZE_ORIGINAL, + // #163561# use mode SC_SIZE_DIRECT: hide for height 0, show for other values + aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, thisAddress.Sheet, SC_SIZE_DIRECT, nTwips, TRUE, TRUE ); } -- cgit From 9f7c8470ae5b47b3a36e6f447228e8ec6f95d0c3 Mon Sep 17 00:00:00 2001 From: Niklas Nebel Date: Wed, 8 Sep 2010 14:20:41 +0200 Subject: mib19: #163497# implement VBA Placement property --- sc/source/ui/vba/vbasheetobject.cxx | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) mode change 100755 => 100644 sc/source/ui/vba/vbasheetobject.cxx (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbasheetobject.cxx b/sc/source/ui/vba/vbasheetobject.cxx old mode 100755 new mode 100644 index 4bd0f1d60547..28e54de859ad --- a/sc/source/ui/vba/vbasheetobject.cxx +++ b/sc/source/ui/vba/vbasheetobject.cxx @@ -38,7 +38,9 @@ #include #include #include +#include #include "vbafont.hxx" +#include "drwlayer.hxx" using ::rtl::OUString; using namespace ::com::sun::star; @@ -237,13 +239,38 @@ void SAL_CALL ScVbaSheetObjectBase::setName( const OUString& rName ) throw (uno: sal_Int32 SAL_CALL ScVbaSheetObjectBase::getPlacement() throw (uno::RuntimeException) { - // TODO - return excel::XlPlacement::xlMoveAndSize; + sal_Int32 nRet = excel::XlPlacement::xlMoveAndSize; + SvxShape* pShape = SvxShape::getImplementation( mxShape ); + if(pShape) + { + SdrObject* pObj = pShape->GetSdrObject(); + if (pObj) + { + ScAnchorType eType = ScDrawLayer::GetAnchor(pObj); + if (eType == SCA_PAGE) + nRet = excel::XlPlacement::xlFreeFloating; + } + } + return nRet; } -void SAL_CALL ScVbaSheetObjectBase::setPlacement( sal_Int32 /*nPlacement*/ ) throw (uno::RuntimeException) +void SAL_CALL ScVbaSheetObjectBase::setPlacement( sal_Int32 nPlacement ) throw (uno::RuntimeException) { - // TODO + SvxShape* pShape = SvxShape::getImplementation( mxShape ); + if(pShape) + { + SdrObject* pObj = pShape->GetSdrObject(); + if (pObj) + { + ScAnchorType eType = SCA_CELL; + if ( nPlacement == excel::XlPlacement::xlFreeFloating ) + eType = SCA_PAGE; + + // xlMove is not supported, treated as SCA_CELL (xlMoveAndSize) + + ScDrawLayer::SetAnchor(pObj, eType); + } + } } sal_Bool SAL_CALL ScVbaSheetObjectBase::getPrintObject() throw (uno::RuntimeException) -- cgit From 369f4c3d1fca0b4d3b96a9085169545abc641736 Mon Sep 17 00:00:00 2001 From: Thomas Benisch Date: Wed, 8 Sep 2010 19:23:58 +0200 Subject: mib19: #163530# Filter box shows only entry of first row --- sc/source/ui/vba/vbarange.cxx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 230af4f5d5e3..25d19fb76687 100755 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -4355,6 +4355,20 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const { RangeHelper multiCellRange( mxRange ); autoFiltAddress = multiCellRange.getCellRangeAddressable()->getRangeAddress(); + // #163530# Filter box shows only entry of first row + ScDocument* pDocument = ( pShell ? pShell->GetDocument() : NULL ); + if ( pDocument ) + { + SCCOL nStartCol = autoFiltAddress.StartColumn; + SCROW nStartRow = autoFiltAddress.StartRow; + SCCOL nEndCol = autoFiltAddress.EndColumn; + SCROW nEndRow = autoFiltAddress.EndRow; + pDocument->GetDataArea( autoFiltAddress.Sheet, nStartCol, nStartRow, nEndCol, nEndRow, TRUE, true ); + autoFiltAddress.StartColumn = nStartCol; + autoFiltAddress.StartRow = nStartRow; + autoFiltAddress.EndColumn = nEndCol; + autoFiltAddress.EndRow = nEndRow; + } } uno::Reference< sheet::XDatabaseRanges > xDBRanges = lcl_GetDataBaseRanges( pShell ); @@ -4374,13 +4388,9 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW ); // set autofilt xDBRangeProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ), uno::Any(sal_True) ); - // set header + // set header (autofilter always need column headers) uno::Reference< beans::XPropertySet > xFiltProps( xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY_THROW ); - sal_Bool bHasColHeader = sal_False; - ScDocument* pDoc = pShell ? pShell->GetDocument() : NULL; - - bHasColHeader = pDoc->HasColHeader( static_cast< SCCOL >( autoFiltAddress.StartColumn ), static_cast< SCROW >( autoFiltAddress.StartRow ), static_cast< SCCOL >( autoFiltAddress.EndColumn ), static_cast< SCROW >( autoFiltAddress.EndRow ), static_cast< SCTAB >( autoFiltAddress.Sheet ) ) ? sal_True : sal_False; - xFiltProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ContainsHeader") ), uno::Any( bHasColHeader ) ); + xFiltProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ContainsHeader") ), uno::Any( sal_True ) ); } -- cgit From d75e8a885ff260f25ec71abb0c4c772453f504fb Mon Sep 17 00:00:00 2001 From: Niklas Nebel Date: Thu, 9 Sep 2010 13:55:29 +0200 Subject: mib19: #163560# use default cell font and RefDevice for column width --- sc/source/ui/vba/vbarange.cxx | 61 ++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 42 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 25d19fb76687..d32ad0a4b41e 100755 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -172,6 +172,9 @@ using namespace ::ooo::vba; using namespace ::com::sun::star; using ::std::vector; +// difference between VBA and file format width, in character units +const double fExtraWidth = 182.0 / 256.0; + // * 1 point = 1/72 inch = 20 twips // * 1 inch = 72 points = 1440 twips // * 1 cm = 567 twips @@ -3614,15 +3617,6 @@ ScVbaRange::getDefaultMethodName( ) throw (uno::RuntimeException) } -uno::Reference< awt::XDevice > -getDeviceFromDoc( const uno::Reference< frame::XModel >& xModel ) throw( uno::RuntimeException ) -{ - uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); - uno::Reference< frame::XFrame> xFrame( xController->getFrame(), uno::UNO_QUERY_THROW ); - uno::Reference< awt::XDevice > xDevice( xFrame->getComponentWindow(), uno::UNO_QUERY_THROW ); - return xDevice; -} - // returns calc internal col. width ( in points ) double ScVbaRange::getCalcColWidth( const table::CellRangeAddress& rAddress) throw (uno::RuntimeException) @@ -3645,29 +3639,16 @@ ScVbaRange::getCalcRowHeight( const table::CellRangeAddress& rAddress ) throw (u } // return Char Width in points -double getDefaultCharWidth( const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) -{ - const static rtl::OUString sDflt( RTL_CONSTASCII_USTRINGPARAM("Default")); - const static rtl::OUString sCharFontName( RTL_CONSTASCII_USTRINGPARAM("CharFontName")); - const static rtl::OUString sPageStyles( RTL_CONSTASCII_USTRINGPARAM("PageStyles")); - // get the font from the default style - uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( xModel, uno::UNO_QUERY_THROW ); - uno::Reference< container::XNameAccess > xNameAccess( xStyleSupplier->getStyleFamilies(), uno::UNO_QUERY_THROW ); - uno::Reference< container::XNameAccess > xNameAccess2( xNameAccess->getByName( sPageStyles ), uno::UNO_QUERY_THROW ); - uno::Reference< beans::XPropertySet > xProps( xNameAccess2->getByName( sDflt ), uno::UNO_QUERY_THROW ); - rtl::OUString sFontName; - xProps->getPropertyValue( sCharFontName ) >>= sFontName; - - uno::Reference< awt::XDevice > xDevice = getDeviceFromDoc( xModel ); - awt::FontDescriptor aDesc; - aDesc.Name = sFontName; - uno::Reference< awt::XFont > xFont( xDevice->getFont( aDesc ), uno::UNO_QUERY_THROW ); - double nCharPixelWidth = xFont->getCharWidth( (sal_Int8)'0' ); - - double nPixelsPerMeter = xDevice->getInfo().PixelPerMeterX; - double nCharWidth = nCharPixelWidth / nPixelsPerMeter; - nCharWidth = nCharWidth * (double)56700;// in twips - return lcl_TwipsToPoints( (USHORT)nCharWidth ); +double getDefaultCharWidth( ScDocShell* pDocShell ) +{ + ScDocument* pDoc = pDocShell->GetDocument(); + OutputDevice* pRefDevice = pDoc->GetRefDevice(); + ScPatternAttr* pAttr = pDoc->GetDefPattern(); + ::Font aDefFont; + pAttr->GetFont( aDefFont, SC_AUTOCOL_BLACK, pRefDevice ); + pRefDevice->SetFont( aDefFont ); + long nCharWidth = pRefDevice->GetTextWidth( String( '0' ) ); // 1/100th mm + return lcl_hmmToPoints( nCharWidth ); } uno::Any SAL_CALL @@ -3685,7 +3666,7 @@ ScVbaRange::getColumnWidth() throw (uno::RuntimeException) if ( pShell ) { uno::Reference< frame::XModel > xModel = pShell->GetModel(); - double defaultCharWidth = getDefaultCharWidth( xModel ); + double defaultCharWidth = getDefaultCharWidth( pShell ); RangeHelper thisRange( mxRange ); table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); sal_Int32 nStartCol = thisAddress.StartColumn; @@ -3700,9 +3681,9 @@ ScVbaRange::getColumnWidth() throw (uno::RuntimeException) if ( nColTwips != nCurTwips ) return aNULL(); } - nColWidth = lcl_Round2DecPlaces( lcl_TwipsToPoints( nColTwips ) ); - if ( xModel.is() ) - nColWidth = nColWidth / defaultCharWidth; + nColWidth = lcl_TwipsToPoints( nColTwips ); + if ( nColWidth != 0.0 ) + nColWidth = ( nColWidth / defaultCharWidth ) - fExtraWidth; } nColWidth = lcl_Round2DecPlaces( nColWidth ); return uno::makeAny( nColWidth ); @@ -3727,11 +3708,8 @@ ScVbaRange::setColumnWidth( const uno::Any& _columnwidth ) throw (uno::RuntimeEx ScDocShell* pDocShell = getScDocShell(); if ( pDocShell ) { - uno::Reference< frame::XModel > xModel = pDocShell->GetModel(); - if ( xModel.is() ) - { - - nColWidth = ( nColWidth * getDefaultCharWidth( xModel ) ); + if ( nColWidth != 0.0 ) + nColWidth = ( nColWidth + fExtraWidth ) * getDefaultCharWidth( pDocShell ); RangeHelper thisRange( mxRange ); table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); USHORT nTwips = lcl_pointsToTwips( nColWidth ); @@ -3745,7 +3723,6 @@ ScVbaRange::setColumnWidth( const uno::Any& _columnwidth ) throw (uno::RuntimeEx nTwips, TRUE, TRUE ); } - } } uno::Any SAL_CALL -- cgit From a7f5a052a807e8e26cfb6012135adbb43348781a Mon Sep 17 00:00:00 2001 From: "Daniel Rentz [dr]" Date: Mon, 13 Sep 2010 17:41:51 +0200 Subject: mib19: #163557# make VBA Application settings globally available for all open workbooks --- sc/source/ui/vba/vbaapplication.cxx | 38 ++++++++++++++++++++++++++++++------- sc/source/ui/vba/vbaapplication.hxx | 7 ++++--- 2 files changed, 35 insertions(+), 10 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index f3965393e919..a53ca5cabe72 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -60,6 +60,7 @@ #include "sc.hrc" #include +#include #include #include @@ -108,11 +109,32 @@ public: ActiveWorkbook( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext) : ScVbaWorkbook( xParent, xContext ){} }; +// ============================================================================ + +/** Global application settings shared by all open workbooks. */ +struct ScVbaAppSettings +{ + sal_Int32 mnCalculation; + sal_Bool mbDisplayAlerts; + sal_Bool mbEnableEvents; + + explicit ScVbaAppSettings(); +}; + +ScVbaAppSettings::ScVbaAppSettings() : + mnCalculation( excel::XlCalculation::xlCalculationAutomatic ), + mbDisplayAlerts( sal_True ), + mbEnableEvents( sal_True ) +{ +} + +struct ScVbaStaticAppSettings : public ::rtl::Static< ScVbaAppSettings, ScVbaStaticAppSettings > {}; + +// ============================================================================ + ScVbaApplication::ScVbaApplication( const uno::Reference& xContext ) : ScVbaApplication_BASE( xContext ), - m_xCalculation( excel::XlCalculation::xlCalculationAutomatic ), - m_bDisplayAlerts( sal_True ), - m_bEnableEvents( sal_True ) + mrAppSettings( ScVbaStaticAppSettings::get() ) { } @@ -415,6 +437,7 @@ ScVbaApplication::setStatusBar( const uno::Any& _statusbar ) throw (uno::Runtime ::sal_Int32 SAL_CALL ScVbaApplication::getCalculation() throw (uno::RuntimeException) { + // TODO: in Excel, this is an application-wide setting uno::Reference xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW); if(xCalc->isAutomaticCalculationEnabled()) return excel::XlCalculation::xlCalculationAutomatic; @@ -425,6 +448,7 @@ ScVbaApplication::getCalculation() throw (uno::RuntimeException) void SAL_CALL ScVbaApplication::setCalculation( ::sal_Int32 _calculation ) throw (uno::RuntimeException) { + // TODO: in Excel, this is an application-wide setting uno::Reference< sheet::XCalculatable > xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW); switch(_calculation) { @@ -704,25 +728,25 @@ ScVbaApplication::getName() throw (uno::RuntimeException) void SAL_CALL ScVbaApplication::setDisplayAlerts(sal_Bool displayAlerts) throw (uno::RuntimeException) { - m_bDisplayAlerts = displayAlerts; + mrAppSettings.mbDisplayAlerts = displayAlerts; } sal_Bool SAL_CALL ScVbaApplication::getDisplayAlerts() throw (uno::RuntimeException) { - return m_bDisplayAlerts; + return mrAppSettings.mbDisplayAlerts; } void SAL_CALL ScVbaApplication::setEnableEvents(sal_Bool bEnable) throw (uno::RuntimeException) { - m_bEnableEvents = bEnable; + mrAppSettings.mbEnableEvents = bEnable; } sal_Bool SAL_CALL ScVbaApplication::getEnableEvents() throw (uno::RuntimeException) { - return m_bEnableEvents; + return mrAppSettings.mbEnableEvents; } void SAL_CALL diff --git a/sc/source/ui/vba/vbaapplication.hxx b/sc/source/ui/vba/vbaapplication.hxx index a7be5feb1d27..91d09d006c5b 100644 --- a/sc/source/ui/vba/vbaapplication.hxx +++ b/sc/source/ui/vba/vbaapplication.hxx @@ -39,12 +39,13 @@ //typedef InheritedHelperInterfaceImpl1< ov::excel::XApplication > ScVbaApplication_BASE; typedef cppu::ImplInheritanceHelper1< VbaApplicationBase, ov::excel::XApplication > ScVbaApplication_BASE; +struct ScVbaAppSettings; + class ScVbaApplication : public ScVbaApplication_BASE { private: - sal_Int32 m_xCalculation; - sal_Bool m_bDisplayAlerts; - sal_Bool m_bEnableEvents; + // note: member variables moved to struct "ScVbaAppSettings", see cxx file, to be shared by all application instances + ScVbaAppSettings& mrAppSettings; rtl::OUString getOfficePath( const rtl::OUString& sPath ) throw ( css::uno::RuntimeException ); -- cgit From 676af9dc74cd77e16e82b716ad3bb8410cabf61f Mon Sep 17 00:00:00 2001 From: "Daniel Rentz [dr]" Date: Mon, 13 Sep 2010 17:47:04 +0200 Subject: mib19: #163557# cleanup VBA XDocuments implementation, trigger Workbook_Open event when creating a new Excel workbook via Workbooks.Add --- sc/source/ui/vba/vbaworkbooks.cxx | 66 +++++++++++++++++++++++++++++++-------- sc/source/ui/vba/vbaworkbooks.hxx | 5 +-- 2 files changed, 54 insertions(+), 17 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbaworkbooks.cxx b/sc/source/ui/vba/vbaworkbooks.cxx index 7efee1505dcb..194d3d1b9656 100644 --- a/sc/source/ui/vba/vbaworkbooks.cxx +++ b/sc/source/ui/vba/vbaworkbooks.cxx @@ -46,7 +46,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -81,7 +83,7 @@ void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& if( xLibContainer.is() ) { - if( !xLibContainer->hasByName( aPrjName ) ) + if( !xLibContainer->hasByName( aPrjName ) ) xLibContainer->createLibrary( aPrjName ); uno::Any aLibAny = xLibContainer->getByName( aPrjName ); uno::Reference< container::XNameContainer > xLib; @@ -130,6 +132,18 @@ void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& } } } + + /* Trigger the Workbook_Open event, event processor will register + itself as listener for specific events. */ + try + { + uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pShell->GetDocument()->GetVbaEventProcessor(), uno::UNO_SET_THROW ); + uno::Sequence< uno::Any > aArgs; + xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_OPEN, aArgs ); + } + catch( uno::Exception& ) + { + } } } @@ -200,9 +214,41 @@ ScVbaWorkbooks::createCollectionObject( const css::uno::Any& aSource ) uno::Any SAL_CALL -ScVbaWorkbooks::Add() throw (uno::RuntimeException) +ScVbaWorkbooks::Add( const uno::Any& Template ) throw (uno::RuntimeException) { - uno::Reference xSpreadDoc( VbaDocumentsBase::Add() , uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheetDocument > xSpreadDoc; + sal_Int32 nWorkbookType = 0; + ::rtl::OUString aTemplateFileName; + if( Template >>= nWorkbookType ) + { + // nWorkbookType is a constant from XlWBATemplate (added in Excel 2007) + // TODO: create chart-sheet if supported by Calc + + xSpreadDoc.set( createDocument(), uno::UNO_QUERY_THROW ); + // create a document with one sheet only + uno::Reference< sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_SET_THROW ); + uno::Reference< container::XIndexAccess > xSheetsIA( xSheets, uno::UNO_QUERY_THROW ); + while( xSheetsIA->getCount() > 1 ) + { + uno::Reference< container::XNamed > xSheetName( xSheetsIA->getByIndex( xSheetsIA->getCount() - 1 ), uno::UNO_QUERY_THROW ); + xSheets->removeByName( xSheetName->getName() ); + } + } + else if( Template >>= aTemplateFileName ) + { + // TODO: create document from template + xSpreadDoc.set( createDocument(), uno::UNO_QUERY_THROW ); + } + else if( !Template.hasValue() ) + { + // regular spreadsheet document with configured number of sheets + xSpreadDoc.set( createDocument(), uno::UNO_QUERY_THROW ); + } + else + { + // illegal argument + throw uno::RuntimeException(); + } // need to set up the document modules ( and vba mode ) here setUpDocumentModules( xSpreadDoc ); @@ -211,10 +257,10 @@ ScVbaWorkbooks::Add() throw (uno::RuntimeException) return uno::Any(); } -void +void SAL_CALL ScVbaWorkbooks::Close() throw (uno::RuntimeException) { - VbaDocumentsBase::Close(); + closeDocuments(); } bool @@ -254,7 +300,7 @@ ScVbaWorkbooks::getFileFilterType( const rtl::OUString& rFileName ) } // #TODO# #FIXME# can any of the unused params below be used? -uno::Any +uno::Any SAL_CALL ScVbaWorkbooks::Open( const rtl::OUString& rFileName, const uno::Any& /*UpdateLinks*/, const uno::Any& ReadOnly, const uno::Any& Format, const uno::Any& /*Password*/, const uno::Any& /*WriteResPassword*/, const uno::Any& /*IgnoreReadOnlyRecommended*/, const uno::Any& /*Origin*/, const uno::Any& Delimiter, const uno::Any& /*Editable*/, const uno::Any& /*Notify*/, const uno::Any& /*Converter*/, const uno::Any& /*AddToMru*/ ) throw (uno::RuntimeException) { // we need to detect if this is a URL, if not then assume its a file path @@ -333,7 +379,7 @@ ScVbaWorkbooks::Open( const rtl::OUString& rFileName, const uno::Any& /*UpdateLi else if ( !isSpreadSheetFile( sType ) ) throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Bad Format")), uno::Reference< uno::XInterface >() ); - uno::Reference xSpreadDoc( VbaDocumentsBase::Open( rFileName, ReadOnly, sProps ), uno::UNO_QUERY_THROW ); + uno::Reference xSpreadDoc( openDocument( rFileName, ReadOnly, sProps ), uno::UNO_QUERY_THROW ); uno::Any aRet = getWorkbook( mxContext, xSpreadDoc, mxParent ); uno::Reference< excel::XWorkbook > xWBook( aRet, uno::UNO_QUERY ); if ( xWBook.is() ) @@ -341,12 +387,6 @@ ScVbaWorkbooks::Open( const rtl::OUString& rFileName, const uno::Any& /*UpdateLi return aRet; } -uno::Any -ScVbaWorkbooks::Open( const rtl::OUString& Filename, const uno::Any& ReadOnly, const uno::Sequence< beans::PropertyValue >& rProps ) throw (css::uno::RuntimeException) -{ - return VbaDocumentsBase::Open( Filename, ReadOnly, rProps ); -} - rtl::OUString& ScVbaWorkbooks::getServiceImplName() { diff --git a/sc/source/ui/vba/vbaworkbooks.hxx b/sc/source/ui/vba/vbaworkbooks.hxx index 5d6210244d80..3392829f1a05 100644 --- a/sc/source/ui/vba/vbaworkbooks.hxx +++ b/sc/source/ui/vba/vbaworkbooks.hxx @@ -60,12 +60,9 @@ public: virtual css::uno::Sequence getServiceNames(); // XWorkbooks - virtual css::uno::Any SAL_CALL Add() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Add( const css::uno::Any& Template ) throw (css::uno::RuntimeException); virtual void SAL_CALL Close( ) throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL Open( const ::rtl::OUString& Filename, const css::uno::Any& UpdateLinks, const css::uno::Any& ReadOnly, const css::uno::Any& Format, const css::uno::Any& Password, const css::uno::Any& WriteResPassword, const css::uno::Any& IgnoreReadOnlyRecommended, const css::uno::Any& Origin, const css::uno::Any& Delimiter, const css::uno::Any& Editable, const css::uno::Any& Notify, const css::uno::Any& Converter, const css::uno::Any& AddToMru ) throw (css::uno::RuntimeException); - - // VbaDocumentsBase / XDocumentsBase (to avoid warning C4266 for hiding function on wntmsci) - virtual css::uno::Any SAL_CALL Open( const ::rtl::OUString& Filename, const css::uno::Any& ReadOnly, const css::uno::Sequence< css::beans::PropertyValue >& rProps ) throw (css::uno::RuntimeException); }; #endif /* SC_VBA_WORKBOOKS_HXX */ -- cgit From 389977a4e4c8678ec1f5de6b93c08232cac248c4 Mon Sep 17 00:00:00 2001 From: Niklas Nebel Date: Mon, 13 Sep 2010 20:07:15 +0200 Subject: mib19: #163566# if the VBA event processor is set, check HasAnyCalcNotification before HasAnySheetEventScript in ScModelObj::Notify --- sc/source/ui/unoobj/docuno.cxx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 3d3f0f479601..89193ad8ddf0 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -590,8 +590,21 @@ void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) DELETEZ( pPrintFuncCache ); // handle "OnCalculate" sheet events (search also for VBA event handlers) - if ( pDocShell && pDocShell->GetDocument()->HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE, true ) ) - HandleCalculateEvents(); + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + if ( pDoc->GetVbaEventProcessor().is() ) + { + // If the VBA event processor is set, HasAnyCalcNotification is much faster than HasAnySheetEventScript + if ( pDoc->HasAnyCalcNotification() && pDoc->HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE, true ) ) + HandleCalculateEvents(); + } + else + { + if ( pDoc->HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE ) ) + HandleCalculateEvents(); + } + } } } else if ( rHint.ISA( ScPointerChangedHint ) ) -- cgit From f84ff82a7fd78ca8584e4b56d98d83170b60e86c Mon Sep 17 00:00:00 2001 From: Niklas Nebel Date: Tue, 14 Sep 2010 16:39:22 +0200 Subject: mib19: #163625# for empty status bar text, call XStatusIndicator::end --- sc/source/ui/vba/vbaapplication.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index a53ca5cabe72..5bb44c126fdf 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -418,8 +418,10 @@ ScVbaApplication::setStatusBar( const uno::Any& _statusbar ) throw (uno::Runtime if( _statusbar >>= sText ) { setDisplayStatusBar( sal_True ); - xStatusIndicator->start( sText, 100 ); - //xStatusIndicator->setText( sText ); + if ( sText.getLength() ) + xStatusIndicator->start( sText, 100 ); + else + xStatusIndicator->end(); // restore normal state for empty text } else if( _statusbar >>= bDefault ) { -- cgit From 3df871eb91f28bdbc8ee07ee5d2f31643d8d4bb4 Mon Sep 17 00:00:00 2001 From: Niklas Nebel Date: Tue, 14 Sep 2010 19:10:26 +0200 Subject: mib19: #163566# compare cursor position in ScDocFunc::NotifyInputHandler --- sc/source/ui/docshell/docfunc.cxx | 4 ++-- sc/source/ui/inc/inputhdl.hxx | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 27112d8c62c2..adbe26abf157 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -851,13 +851,13 @@ BOOL ScDocFunc::PutCell( const ScAddress& rPos, ScBaseCell* pNewCell, BOOL bApi return TRUE; } -void ScDocFunc::NotifyInputHandler( const ScAddress& /* rPos */ ) +void ScDocFunc::NotifyInputHandler( const ScAddress& rPos ) { ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); if ( pViewSh && pViewSh->GetViewData()->GetDocShell() == &rDocShell ) { ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl(); - if ( pInputHdl ) + if ( pInputHdl && pInputHdl->GetCursorPos() == rPos ) { sal_Bool bIsEditMode(pInputHdl->IsEditMode()); diff --git a/sc/source/ui/inc/inputhdl.hxx b/sc/source/ui/inc/inputhdl.hxx index 61974cf7464d..f3eba8b26f6b 100644 --- a/sc/source/ui/inc/inputhdl.hxx +++ b/sc/source/ui/inc/inputhdl.hxx @@ -168,6 +168,8 @@ public: const String& GetEditString(); const String& GetFormString() const { return aFormText; } + const ScAddress& GetCursorPos() const { return aCursorPos; } + BOOL GetTextAndFields( ScEditEngineDefaulter& rDestEngine ); BOOL KeyInput( const KeyEvent& rKEvt, BOOL bStartEdit = FALSE ); -- cgit From 7e98422fec2e9132dee0bacba19f323a4b192509 Mon Sep 17 00:00:00 2001 From: Niklas Nebel Date: Tue, 14 Sep 2010 23:23:30 +0200 Subject: mib19: #163566# use common helper method for ScVbaRange::Cells and ScVbaWorksheet::Cells --- sc/source/ui/vba/vbarange.cxx | 24 ++++++++++++++++++------ sc/source/ui/vba/vbarange.hxx | 6 ++++++ sc/source/ui/vba/vbaworksheet.cxx | 5 ++++- 3 files changed, 28 insertions(+), 7 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index d32ad0a4b41e..95b54cc1f9d2 100755 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -2060,6 +2060,18 @@ ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) thr return xRange->Cells( nRowIndex, nColumnIndex ); } + // Performance: Use a common helper method for ScVbaRange::Cells and ScVbaWorksheet::Cells, + // instead of creating a new ScVbaRange object in often-called ScVbaWorksheet::Cells + return CellsHelper( mxParent, mxContext, mxRange, nRowIndex, nColumnIndex ); +} + +// static +uno::Reference< excel::XRange > +ScVbaRange::CellsHelper( const uno::Reference< ov::XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< css::table::XCellRange >& xRange, + const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) throw(uno::RuntimeException) +{ sal_Int32 nRow = 0, nColumn = 0; sal_Bool bIsIndex = nRowIndex.hasValue(); @@ -2071,7 +2083,7 @@ ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) thr // convertion routine e.g. bSuccess = getValueFromAny( nRow, nRowIndex, getCppuType((sal_Int32*)0) ) if ( nRowIndex.hasValue() && !( nRowIndex >>= nRow ) ) { - uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext ); + uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( xContext ); uno::Any aConverted; try { @@ -2082,7 +2094,7 @@ ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) thr } if ( bIsColumnIndex && !( nColumnIndex >>= nColumn ) ) { - uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext ); + uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( xContext ); uno::Any aConverted; try { @@ -2092,17 +2104,17 @@ ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) thr catch( uno::Exception& ) {} // silence any errors } - RangeHelper thisRange( mxRange ); + RangeHelper thisRange( xRange ); table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); uno::Reference< table::XCellRange > xSheetRange = thisRange.getCellRangeFromSheet(); if( !bIsIndex && !bIsColumnIndex ) // .Cells // #FIXE needs proper parent ( Worksheet ) - return uno::Reference< excel::XRange >( new ScVbaRange( mxParent, mxContext, mxRange ) ); + return uno::Reference< excel::XRange >( new ScVbaRange( xParent, xContext, xRange ) ); sal_Int32 nIndex = --nRow; if( bIsIndex && !bIsColumnIndex ) // .Cells(n) { - uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, ::uno::UNO_QUERY_THROW); + uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, ::uno::UNO_QUERY_THROW); sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount(); if ( !nIndex || nIndex < 0 ) @@ -2115,7 +2127,7 @@ ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) thr --nColumn; nRow = nRow + thisRangeAddress.StartRow; nColumn = nColumn + thisRangeAddress.StartColumn; - return new ScVbaRange( mxParent, mxContext, xSheetRange->getCellRangeByPosition( nColumn, nRow, nColumn, nRow ) ); + return new ScVbaRange( xParent, xContext, xSheetRange->getCellRangeByPosition( nColumn, nRow, nColumn, nRow ) ); } void diff --git a/sc/source/ui/vba/vbarange.hxx b/sc/source/ui/vba/vbarange.hxx index e7488e434f30..a8aada649575 100644 --- a/sc/source/ui/vba/vbarange.hxx +++ b/sc/source/ui/vba/vbarange.hxx @@ -149,6 +149,12 @@ public: const rtl::OUString& sRangeName, ScDocShell* pDocSh, formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_XL_A1 ) throw ( css::uno::RuntimeException ); + static css::uno::Reference< ov::excel::XRange > CellsHelper( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::table::XCellRange >& xRange, + const css::uno::Any &nRowIndex, const css::uno::Any &nColumnIndex ) throw(css::uno::RuntimeException); + // Attributes virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); virtual void SAL_CALL setValue( const css::uno::Any& aValue ) throw ( css::uno::RuntimeException); diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx index 1f31cb7e19ce..c57048d5b148 100644 --- a/sc/source/ui/vba/vbaworksheet.cxx +++ b/sc/source/ui/vba/vbaworksheet.cxx @@ -658,7 +658,10 @@ uno::Reference< excel::XRange > ScVbaWorksheet::Cells( const ::uno::Any &nRow, const ::uno::Any &nCol ) throw (uno::RuntimeException) { - return getSheetRange()->Cells( nRow, nCol ); + // Performance optimization for often-called Cells method: + // Use a common helper method instead of creating a new ScVbaRange object + uno::Reference< table::XCellRange > xRange( getSheet(), uno::UNO_QUERY_THROW ); + return ScVbaRange::CellsHelper( mxParent, mxContext, xRange, nRow, nCol ); } uno::Reference< excel::XRange > -- cgit From bbf445b0244ec56dd37c9230b3c734f2ec843933 Mon Sep 17 00:00:00 2001 From: "Daniel Rentz [dr]" Date: Wed, 15 Sep 2010 14:11:13 +0200 Subject: mib19: #163640# do not fire selection change events when changing/insertintg/deleting sheets --- sc/source/ui/vba/vbaapplication.cxx | 5 ++ sc/source/ui/vba/vbaapplication.hxx | 3 + sc/source/ui/vba/vbaeventshelper.cxx | 109 ++++++++++++++++++++--------------- sc/source/ui/vba/vbaeventshelper.hxx | 8 +-- 4 files changed, 72 insertions(+), 53 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index 5bb44c126fdf..30d4bd4d39a0 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -142,6 +142,11 @@ ScVbaApplication::~ScVbaApplication() { } +/*static*/ bool ScVbaApplication::getDocumentEventsEnabled() +{ + return ScVbaStaticAppSettings::get().mbEnableEvents; +} + SfxObjectShell* ScVbaApplication::GetDocShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) { return static_cast< SfxObjectShell* >( excel::getDocShell( xModel ) ); diff --git a/sc/source/ui/vba/vbaapplication.hxx b/sc/source/ui/vba/vbaapplication.hxx index 91d09d006c5b..bb696c967a37 100644 --- a/sc/source/ui/vba/vbaapplication.hxx +++ b/sc/source/ui/vba/vbaapplication.hxx @@ -56,6 +56,9 @@ public: ScVbaApplication( const css::uno::Reference< css::uno::XComponentContext >& m_xContext ); virtual ~ScVbaApplication(); + /** Returns true, if VBA document events are enabled. */ + static bool getDocumentEventsEnabled(); + virtual SfxObjectShell* GetDocShell( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); // XExactName diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx index 996bf52e0794..86d5f643a8b2 100755 --- a/sc/source/ui/vba/vbaeventshelper.cxx +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -48,6 +48,7 @@ #include "cellsuno.hxx" #include "convuno.hxx" +#include "vbaapplication.hxx" using namespace ::com::sun::star; using namespace ::com::sun::star::script::vba::VBAEventId; @@ -55,6 +56,40 @@ using namespace ::ooo::vba; // ============================================================================ +namespace { + +/** Extracts a sheet index from the specified element of the passed sequence. + The element may be an integer, or a Calc range or ranges object. */ +SCTAB lclGetTabFromArgs( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) throw (lang::IllegalArgumentException) +{ + VbaEventsHelperBase::checkArgument( rArgs, nIndex ); + + // first try to extract a sheet index + SCTAB nTab = -1; + if( rArgs[ nIndex ] >>= nTab ) + return nTab; + + // next, try single range object + uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable = getXSomethingFromArgs< sheet::XCellRangeAddressable >( rArgs, nIndex ); + if( xCellRangeAddressable.is() ) + return xCellRangeAddressable->getRangeAddress().Sheet; + + // at last, try range list + uno::Reference< sheet::XSheetCellRangeContainer > xRanges = getXSomethingFromArgs< sheet::XSheetCellRangeContainer >( rArgs, nIndex ); + if( xRanges.is() ) + { + uno::Sequence< table::CellRangeAddress > aRangeAddresses = xRanges->getRangeAddresses(); + if( aRangeAddresses.getLength() > 0 ) + return aRangeAddresses[ 0 ].Sheet; + } + + throw lang::IllegalArgumentException(); +} + +} // namespace + +// ============================================================================ + typedef ::cppu::WeakImplHelper4< awt::XWindowListener, util::XCloseListener, frame::XBorderResizeListener, util::XChangesListener > ScVbaEventsListener_BASE; @@ -475,25 +510,13 @@ bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, if( (rInfo.maUserData >>= bSheetEvent) && bSheetEvent ) rEventQueue.push_back( EventQueueEntry( rInfo.mnEventId + USERDEFINED_START, rArgs ) ); - /* For document events: get Application object and check if events are - enabled via EnableEvents symbol (this is an Excel-only attribute). + /* For document events: check if events are enabled via the + Application.EnableEvents symbol (this is an Excel-only attribute). Check this again for every event, as the event handler may change the state of the EnableEvents symbol. Global events such as AUTO_OPEN and AUTO_CLOSE are always enabled. */ if( rInfo.meType == EVENTHANDLER_DOCUMENT ) - { - // reference to application is held weakly, get application on first try - uno::Reference< excel::XApplication > xApplication( mxApplication.get(), uno::UNO_QUERY ); - if( !xApplication.is() ) - { - uno::Any aVBAGlobals; - mpShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aVBAGlobals ); - uno::Reference< XHelperInterface > xHelperInterface( aVBAGlobals, uno::UNO_QUERY_THROW ); - xApplication.set( xHelperInterface->Application(), uno::UNO_QUERY_THROW ); - mxApplication = xApplication; - } - bExecuteEvent = xApplication->getEnableEvents(); - } + bExecuteEvent = ScVbaApplication::getDocumentEventsEnabled(); } return bExecuteEvent; @@ -618,7 +641,7 @@ void ScVbaEventsHelper::implPostProcessEvent( EventQueue& rEventQueue, { bool bSheetEvent = false; rInfo.maUserData >>= bSheetEvent; - SCTAB nTab = bSheetEvent ? getTabFromArgs( rArgs, 0 ) : -1; + SCTAB nTab = bSheetEvent ? lclGetTabFromArgs( rArgs, 0 ) : -1; if( bSheetEvent && (nTab < 0) ) throw lang::IllegalArgumentException(); @@ -632,43 +655,37 @@ void ScVbaEventsHelper::implPostProcessEvent( EventQueue& rEventQueue, // private -------------------------------------------------------------------- -SCTAB ScVbaEventsHelper::getTabFromArgs( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) throw (lang::IllegalArgumentException) -{ - checkArgument( rArgs, nIndex ); - - // first try to extract a sheet index - SCTAB nTab = -1; - if( rArgs[ nIndex ] >>= nTab ) - return nTab; +namespace { - // next, try single range object - uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable = getXSomethingFromArgs< sheet::XCellRangeAddressable >( rArgs, nIndex ); - if( xCellRangeAddressable.is() ) - return xCellRangeAddressable->getRangeAddress().Sheet; +/** Compares the passed range lists representing sheet selections. Ignores + selections that refer to different sheets (returns false in this case). */ +bool lclSelectionChanged( const ScRangeList& rLeft, const ScRangeList& rRight ) +{ + // one of the range lists empty? -> return false, if both lists empty + bool bLeftEmpty = rLeft.Count() == 0; + bool bRightEmpty = rRight.Count() == 0; + if( bLeftEmpty || bRightEmpty ) + return !(bLeftEmpty && bRightEmpty); - // at last, try range list - uno::Reference< sheet::XSheetCellRangeContainer > xRanges = getXSomethingFromArgs< sheet::XSheetCellRangeContainer >( rArgs, nIndex ); - if( xRanges.is() ) - { - uno::Sequence< table::CellRangeAddress > aRangeAddresses = xRanges->getRangeAddresses(); - if( aRangeAddresses.getLength() > 0 ) - return aRangeAddresses[ 0 ].Sheet; - } + // check sheet indexes of the range lists (assuming that all ranges in a list are on the same sheet) + if( rLeft.GetObject( 0 )->aStart.Tab() != rRight.GetObject( 0 )->aStart.Tab() ) + return false; - throw lang::IllegalArgumentException(); + // compare all ranges + return rLeft != rRight; } +} // namespace + bool ScVbaEventsHelper::isSelectionChanged( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) throw (lang::IllegalArgumentException, uno::RuntimeException) { + uno::Reference< uno::XInterface > xOldSelection( maOldSelection, uno::UNO_QUERY ); uno::Reference< uno::XInterface > xNewSelection = getXSomethingFromArgs< uno::XInterface >( rArgs, nIndex, false ); - if( ScCellRangesBase* pNewCellRanges = ScCellRangesBase::getImplementation( xNewSelection ) ) - { - bool bChanged = maOldSelection != pNewCellRanges->GetRangeList(); - maOldSelection = pNewCellRanges->GetRangeList(); - return bChanged; - } - maOldSelection.Clear(); - return true; + ScCellRangesBase* pOldCellRanges = ScCellRangesBase::getImplementation( xOldSelection ); + ScCellRangesBase* pNewCellRanges = ScCellRangesBase::getImplementation( xNewSelection ); + bool bChanged = !pOldCellRanges || !pNewCellRanges || lclSelectionChanged( pOldCellRanges->GetRangeList(), pNewCellRanges->GetRangeList() ); + maOldSelection <<= xNewSelection; + return bChanged; } uno::Any ScVbaEventsHelper::createWorksheet( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) const @@ -678,7 +695,7 @@ uno::Any ScVbaEventsHelper::createWorksheet( const uno::Sequence< uno::Any >& rA // directly from basic and register them as listeners // extract sheet index, will throw, if parameter is invalid - SCTAB nTab = getTabFromArgs( rArgs, nIndex ); + SCTAB nTab = lclGetTabFromArgs( rArgs, nIndex ); // create Workbook uno::Sequence< uno::Any > aArgs( 2 ); diff --git a/sc/source/ui/vba/vbaeventshelper.hxx b/sc/source/ui/vba/vbaeventshelper.hxx index eaac96117d32..f1e8a4fb712d 100755 --- a/sc/source/ui/vba/vbaeventshelper.hxx +++ b/sc/source/ui/vba/vbaeventshelper.hxx @@ -33,8 +33,6 @@ #include "excelvbahelper.hxx" #include "rangelst.hxx" -namespace ooo { namespace vba { namespace excel { class XApplication; } } } - class ScVbaEventsListener; // ============================================================================ @@ -57,9 +55,6 @@ protected: virtual ::rtl::OUString implGetDocumentModuleName( const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) const throw (css::lang::IllegalArgumentException); private: - /** Extracts a sheet index from the first element of the passed sequence. The - element may be an integer, or a Calc range or ranges object. */ - static SCTAB getTabFromArgs( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) throw (css::lang::IllegalArgumentException); /** Checks if selection has been changed compared to selection of last call. @return true, if the selection has been changed. */ bool isSelectionChanged( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); @@ -74,11 +69,10 @@ private: css::uno::Any createWindow() const throw (css::uno::RuntimeException); private: - mutable css::uno::WeakReference< ov::excel::XApplication > mxApplication; ::rtl::Reference< ScVbaEventsListener > mxListener; + css::uno::Any maOldSelection; ScDocShell* mpDocShell; ScDocument* mpDoc; - ScRangeList maOldSelection; bool mbOpened; }; -- cgit From afea0155c26d0864a9a629b2453afff3490e9bed Mon Sep 17 00:00:00 2001 From: Niklas Nebel Date: Wed, 15 Sep 2010 18:01:02 +0200 Subject: mib19: #163641# use clipboard content in ScVbaRange::Insert only if it was copied by implnCut/implnCopy --- sc/source/ui/app/transobj.cxx | 8 +++++++- sc/source/ui/inc/transobj.hxx | 3 +++ sc/source/ui/vba/excelvbahelper.cxx | 17 +++++++++++++++++ sc/source/ui/vba/vbarange.cxx | 11 +++++++---- 4 files changed, 34 insertions(+), 5 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx index 4b268b9da791..e6b8b3b5049a 100644 --- a/sc/source/ui/app/transobj.cxx +++ b/sc/source/ui/app/transobj.cxx @@ -134,7 +134,8 @@ ScTransferObj::ScTransferObj( ScDocument* pClipDoc, const TransferableObjectDesc nDragHandleY( 0 ), nDragSourceFlags( 0 ), bDragWasInternal( FALSE ), - bUsedForLink( FALSE ) + bUsedForLink( FALSE ), + bUseInApi( false ) { DBG_ASSERT(pDoc->IsClipboard(), "wrong document"); @@ -540,6 +541,11 @@ void ScTransferObj::SetDragWasInternal() bDragWasInternal = TRUE; } +void ScTransferObj::SetUseInApi( bool bSet ) +{ + bUseInApi = bSet; +} + ScDocument* ScTransferObj::GetSourceDocument() { ScDocShell* pSourceDocSh = GetSourceDocShell(); diff --git a/sc/source/ui/inc/transobj.hxx b/sc/source/ui/inc/transobj.hxx index e2dbad485812..546637c726d0 100644 --- a/sc/source/ui/inc/transobj.hxx +++ b/sc/source/ui/inc/transobj.hxx @@ -64,6 +64,7 @@ private: BOOL bDragWasInternal; BOOL bUsedForLink; bool bHasFiltered; // if has filtered rows + bool bUseInApi; // to recognize clipboard content copied from API void InitDocShell(); static void StripRefs( ScDocument* pDoc, SCCOL nStartX, SCROW nStartY, @@ -93,6 +94,7 @@ public: SCTAB GetVisibleTab() const { return nVisibleTab; } USHORT GetDragSourceFlags() const { return nDragSourceFlags; } bool HasFilteredRows() const { return bHasFiltered; } + bool GetUseInApi() const { return bUseInApi; } ScDocShell* GetSourceDocShell(); ScDocument* GetSourceDocument(); ScMarkData GetSourceMarkData(); @@ -103,6 +105,7 @@ public: void SetDragSource( ScDocShell* pSourceShell, const ScMarkData& rMark ); void SetDragSourceFlags( USHORT nFlags ); void SetDragWasInternal(); + SC_DLLPUBLIC void SetUseInApi( bool bSet ); static SC_DLLPUBLIC ScTransferObj* GetOwnClipboard( Window* pUIWin ); diff --git a/sc/source/ui/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx index 2c39d7154b4b..2813d928eba8 100644 --- a/sc/source/ui/vba/excelvbahelper.cxx +++ b/sc/source/ui/vba/excelvbahelper.cxx @@ -150,7 +150,14 @@ implnCopy( const uno::Reference< frame::XModel>& xModel ) { ScTabViewShell* pViewShell = getBestViewShell( xModel ); if ( pViewShell ) + { pViewShell->CopyToClip(NULL,false,false,true); + + // mark the copied transfer object so it is used in ScVbaRange::Insert + ScTransferObj* pClipObj = ScTransferObj::GetOwnClipboard( NULL ); + if (pClipObj) + pClipObj->SetUseInApi( true ); + } } void @@ -158,7 +165,14 @@ implnCut( const uno::Reference< frame::XModel>& xModel ) { ScTabViewShell* pViewShell = getBestViewShell( xModel ); if ( pViewShell ) + { pViewShell->CutToClip( NULL, TRUE ); + + // mark the copied transfer object so it is used in ScVbaRange::Insert + ScTransferObj* pClipObj = ScTransferObj::GetOwnClipboard( NULL ); + if (pClipObj) + pClipObj->SetUseInApi( true ); + } } void implnPasteSpecial( const uno::Reference< frame::XModel>& xModel, USHORT nFlags,USHORT nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose) @@ -181,7 +195,10 @@ void implnPasteSpecial( const uno::Reference< frame::XModel>& xModel, USHORT nFl ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin ); ScDocument* pDoc = NULL; if ( pOwnClip ) + { pDoc = pOwnClip->GetDocument(); + pOwnClip->SetUseInApi( false ); // don't use in Insert after it was pasted once + } pTabViewShell->PasteFromClip( nFlags, pDoc, nFunction, bSkipEmpty, bTranspose, bAsLink, eMoveMode, IDF_NONE, TRUE ); diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 95b54cc1f9d2..891a5a36ecfd 100755 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -123,6 +123,7 @@ #include #include #include "docfunc.hxx" +#include "transobj.hxx" #include #include @@ -4547,10 +4548,8 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const } void SAL_CALL -ScVbaRange::Insert( const uno::Any& Shift, const uno::Any& CopyOrigin ) throw (uno::RuntimeException) +ScVbaRange::Insert( const uno::Any& Shift, const uno::Any& /* CopyOrigin */ ) throw (uno::RuntimeException) { - sal_Bool bCopyOrigin = sal_True; - CopyOrigin >>= bCopyOrigin; // It appears ( from the web ) that the undocumented CopyOrigin // param should contain member of enum XlInsertFormatOrigin // which can have values xlFormatFromLeftOrAbove or xlFormatFromRightOrBelow @@ -4585,7 +4584,11 @@ ScVbaRange::Insert( const uno::Any& Shift, const uno::Any& CopyOrigin ) throw (u table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW ); xCellRangeMove->insertCells( thisAddress, mode ); - if ( bCopyOrigin ) + + // Paste from clipboard only if the clipboard content was copied via VBA, and not already pasted via VBA again. + // "Insert" behavior should not depend on random clipboard content previously copied by the user. + ScTransferObj* pClipObj = ScTransferObj::GetOwnClipboard( NULL ); + if ( pClipObj && pClipObj->GetUseInApi() ) { // After the insert ( this range ) actually has moved ScRange aRange( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCROW >( thisAddress.StartRow ), static_cast< SCTAB >( thisAddress.Sheet ), static_cast< SCCOL >( thisAddress.EndColumn ), static_cast< SCROW >( thisAddress.EndRow ), static_cast< SCTAB >( thisAddress.Sheet ) ); -- cgit From 5469a815aebac1f954c674c730d27163aff1a457 Mon Sep 17 00:00:00 2001 From: Christian Lippka Date: Fri, 17 Sep 2010 13:52:02 +0200 Subject: mib19: #163566# do not throw assertion if container is not available --- sc/source/ui/vba/vbaworksheet.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx index c57048d5b148..aa7ee3932b08 100644 --- a/sc/source/ui/vba/vbaworksheet.cxx +++ b/sc/source/ui/vba/vbaworksheet.cxx @@ -917,7 +917,8 @@ ScVbaWorksheet::getFormControls() // get the www-standard container ( maybe we should access the // 'www-standard' by name rather than index, this seems an // implementation detail - xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW ); + if( xIndexAccess->hasElements() ) + xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY ); } catch( uno::Exception& ) -- cgit From 1fd5a79a0b542ae5a97d45d14106fbcc1645cd22 Mon Sep 17 00:00:00 2001 From: "Daniel Rentz [dr]" Date: Fri, 17 Sep 2010 15:28:21 +0200 Subject: mib19: #163556# preserve VBA compatibility in ODF roundtrip --- sc/source/ui/vba/vbaworkbooks.cxx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbaworkbooks.cxx b/sc/source/ui/vba/vbaworkbooks.cxx index 194d3d1b9656..a9f1970be34e 100644 --- a/sc/source/ui/vba/vbaworkbooks.cxx +++ b/sc/source/ui/vba/vbaworkbooks.cxx @@ -75,11 +75,15 @@ void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& ScDocShell* pShell = excel::getDocShell( xModel ); if ( pShell ) { + String aPrjName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) ); + pShell->GetBasicManager()->SetName( aPrjName ); + + /* Set library container to VBA compatibility mode. This will create + the VBA Globals object and store it in the Basic manager of the + document. */ uno::Reference xLibContainer = pShell->GetBasicContainer(); uno::Reference xVBACompat( xLibContainer, uno::UNO_QUERY_THROW ); xVBACompat->setVBACompatibilityMode( sal_True ); - String aPrjName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) ); - pShell->GetBasicManager()->SetName( aPrjName ); if( xLibContainer.is() ) { @@ -92,8 +96,6 @@ void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& { uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY_THROW ); uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY_THROW); - // bootstrap vbaglobals - xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAGlobals"))); uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAObjectModuleObjectProvider"))), uno::UNO_QUERY_THROW ); // set up the module info for the workbook and sheets in the nealy created // spreadsheet -- cgit From 01c39c4385fb9a3668ba308d58136925eb232230 Mon Sep 17 00:00:00 2001 From: "Daniel Rentz [dr]" Date: Fri, 17 Sep 2010 18:42:00 +0200 Subject: mib19: set correct Parent for objects (ranges, sheets) passed to VBA event handlers --- sc/source/ui/vba/excelvbahelper.cxx | 62 ++++++++++++++++++++---------- sc/source/ui/vba/excelvbahelper.hxx | 73 +++++++++++++++++++++--------------- sc/source/ui/vba/vbaeventshelper.cxx | 32 +++++----------- 3 files changed, 96 insertions(+), 71 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx index 2813d928eba8..42a415d68e32 100644 --- a/sc/source/ui/vba/excelvbahelper.cxx +++ b/sc/source/ui/vba/excelvbahelper.cxx @@ -24,24 +24,25 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ -#include + #include "excelvbahelper.hxx" + +#include +#include +#include "docuno.hxx" #include "tabvwsh.hxx" #include "transobj.hxx" #include "scmod.hxx" #include "cellsuno.hxx" -#include -#include + +namespace ooo { +namespace vba { +namespace excel { using namespace ::com::sun::star; using namespace ::ooo::vba; -namespace ooo -{ -namespace vba -{ -namespace excel -{ +// ============================================================================ ScDocShell* GetDocShellFromRange( const uno::Reference< uno::XInterface >& xRange ) throw ( uno::RuntimeException ) { @@ -246,11 +247,10 @@ getViewFrame( const uno::Reference< frame::XModel >& xModel ) return NULL; } -uno::Reference< XHelperInterface > -getUnoSheetModuleObj( const uno::Reference< table::XCellRange >& xRange ) throw ( uno::RuntimeException ) +uno::Reference< vba::XHelperInterface > +getUnoSheetModuleObj( const uno::Reference< sheet::XSpreadsheet >& xSheet ) throw ( uno::RuntimeException ) { - uno::Reference< sheet::XSheetCellRange > xSheetRange( xRange, uno::UNO_QUERY_THROW ); - uno::Reference< beans::XPropertySet > xProps( xSheetRange->getSpreadsheet(), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps( xSheet, uno::UNO_QUERY_THROW ); rtl::OUString sCodeName; xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CodeName") ) ) >>= sCodeName; // #TODO #FIXME ideally we should 'throw' here if we don't get a valid parent, but... it is possible @@ -258,28 +258,52 @@ getUnoSheetModuleObj( const uno::Reference< table::XCellRange >& xRange ) throw // are *NO* special document module objects ( of course being able to switch between vba/non vba mode at // the document in the future could fix this, especially IF the switching of the vba mode takes care to // create the special document module objects if they don't exist. - uno::Reference< XHelperInterface > xParent( ov::getUnoDocModule( sCodeName, GetDocShellFromRange( xRange ) ), uno::UNO_QUERY ); - + uno::Reference< XHelperInterface > xParent( ov::getUnoDocModule( sCodeName, GetDocShellFromRange( xSheet ) ), uno::UNO_QUERY ); return xParent; } +uno::Reference< XHelperInterface > +getUnoSheetModuleObj( const uno::Reference< table::XCellRange >& xRange ) throw ( uno::RuntimeException ) +{ + uno::Reference< sheet::XSheetCellRange > xSheetRange( xRange, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheet > xSheet( xSheetRange->getSpreadsheet(), uno::UNO_SET_THROW ); + return getUnoSheetModuleObj( xSheet ); +} + uno::Reference< XHelperInterface > getUnoSheetModuleObj( const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges ) throw ( uno::RuntimeException ) { uno::Reference< container::XEnumerationAccess > xEnumAccess( xRanges, uno::UNO_QUERY_THROW ); uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration(); uno::Reference< table::XCellRange > xRange( xEnum->nextElement(), uno::UNO_QUERY_THROW ); - return getUnoSheetModuleObj( xRange ); } +uno::Reference< XHelperInterface > +getUnoSheetModuleObj( const uno::Reference< table::XCell >& xCell ) throw ( uno::RuntimeException ) +{ + uno::Reference< sheet::XSheetCellRange > xSheetRange( xCell, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheet > xSheet( xSheetRange->getSpreadsheet(), uno::UNO_SET_THROW ); + return getUnoSheetModuleObj( xSheet ); +} + +uno::Reference< XHelperInterface > +getUnoSheetModuleObj( const uno::Reference< frame::XModel >& xModel, SCTAB nTab ) throw ( uno::RuntimeException ) +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc( xModel, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xSheets( xDoc->getSheets(), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheet > xSheet( xSheets->getByIndex( nTab ), uno::UNO_QUERY_THROW ); + return getUnoSheetModuleObj( xSheet ); +} + SfxItemSet* ScVbaCellRangeAccess::GetDataSet( ScCellRangesBase* pRangeObj ) { return pRangeObj ? pRangeObj->GetCurrentDataSet( true ) : 0; } +// ============================================================================ -} //excel -} //vba -} //ooo +} // namespace excel +} // namespace vba +} // namespace ooo diff --git a/sc/source/ui/vba/excelvbahelper.hxx b/sc/source/ui/vba/excelvbahelper.hxx index da0474e6ceb0..be04fefa1639 100644 --- a/sc/source/ui/vba/excelvbahelper.hxx +++ b/sc/source/ui/vba/excelvbahelper.hxx @@ -27,41 +27,54 @@ #ifndef SC_EXCEL_VBA_HELPER_HXX #define SC_EXCEL_VBA_HELPER_HXX -#include -#include +#include +#include "docsh.hxx" #include #include +#include #include class ScCellRangesBase; -namespace ooo +namespace ooo { +namespace vba { +namespace excel { + +// ============================================================================ + +// nTabs empty means apply zoom to all sheets +void implSetZoom( const css::uno::Reference< css::frame::XModel >& xModel, sal_Int16 nZoom, std::vector< SCTAB >& nTabs ); +void implnCopy( const css::uno::Reference< css::frame::XModel>& xModel ); +void implnPaste ( const css::uno::Reference< css::frame::XModel>& xModel ); +void implnCut( const css::uno::Reference< css::frame::XModel>& xModel ); +void implnPasteSpecial( const css::uno::Reference< css::frame::XModel>& xModel, sal_uInt16 nFlags,sal_uInt16 nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose); +ScTabViewShell* getBestViewShell( const css::uno::Reference< css::frame::XModel>& xModel ) ; +ScDocShell* getDocShell( const css::uno::Reference< css::frame::XModel>& xModel ) ; +ScTabViewShell* getCurrentBestViewShell( const css::uno::Reference< css::uno::XComponentContext >& xContext ); +SfxViewFrame* getViewFrame( const css::uno::Reference< css::frame::XModel >& xModel ); + +css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::sheet::XSpreadsheet >& xSheet ) throw ( css::uno::RuntimeException ); +css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::sheet::XSheetCellRangeContainer >& xRanges ) throw ( css::uno::RuntimeException ); +css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::table::XCellRange >& xRange ) throw ( css::uno::RuntimeException ); +css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::table::XCell >& xCell ) throw ( css::uno::RuntimeException ); +css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::frame::XModel >& xModel, SCTAB nTab ) throw ( css::uno::RuntimeException ); + +ScDocShell* GetDocShellFromRange( const css::uno::Reference< css::uno::XInterface >& xRange ) throw ( css::uno::RuntimeException ); +ScDocument* GetDocumentFromRange( const css::uno::Reference< css::uno::XInterface >& xRange ) throw ( css::uno::RuntimeException ); +css::uno::Reference< css::frame::XModel > GetModelFromRange( const css::uno::Reference< css::uno::XInterface >& xRange ) throw ( css::uno::RuntimeException ); + +// ============================================================================ + +class ScVbaCellRangeAccess { - namespace vba - { - namespace excel - { - // nTabs empty means apply zoom to all sheets - void implSetZoom( const css::uno::Reference< css::frame::XModel >& xModel, sal_Int16 nZoom, std::vector< SCTAB >& nTabs ); - void implnCopy( const css::uno::Reference< css::frame::XModel>& xModel ); - void implnPaste ( const css::uno::Reference< css::frame::XModel>& xModel ); - void implnCut( const css::uno::Reference< css::frame::XModel>& xModel ); - void implnPasteSpecial( const css::uno::Reference< css::frame::XModel>& xModel, sal_uInt16 nFlags,sal_uInt16 nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose); - ScTabViewShell* getBestViewShell( const css::uno::Reference< css::frame::XModel>& xModel ) ; - ScDocShell* getDocShell( const css::uno::Reference< css::frame::XModel>& xModel ) ; - ScTabViewShell* getCurrentBestViewShell( const css::uno::Reference< css::uno::XComponentContext >& xContext ); - SfxViewFrame* getViewFrame( const css::uno::Reference< css::frame::XModel >& xModel ); - css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::sheet::XSheetCellRangeContainer >& xRanges ) throw ( css::uno::RuntimeException ); - css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::table::XCellRange >& xRange ) throw ( css::uno::RuntimeException ); - ScDocShell* GetDocShellFromRange( const css::uno::Reference< css::uno::XInterface >& xRange ) throw ( css::uno::RuntimeException ); - ScDocument* GetDocumentFromRange( const css::uno::Reference< css::uno::XInterface >& xRange ) throw ( css::uno::RuntimeException ); - css::uno::Reference< css::frame::XModel > GetModelFromRange( const css::uno::Reference< css::uno::XInterface >& xRange ) throw ( css::uno::RuntimeException ); - class ScVbaCellRangeAccess - { - public: - static SfxItemSet* GetDataSet( ScCellRangesBase* pRangeObj ); - }; -} -} -} +public: + static SfxItemSet* GetDataSet( ScCellRangesBase* pRangeObj ); +}; + +// ============================================================================ + +} // namespace excel +} // namespace vba +} // namespace ooo + #endif diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx index 86d5f643a8b2..b7438e87160e 100755 --- a/sc/source/ui/vba/vbaeventshelper.cxx +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -691,27 +691,9 @@ bool ScVbaEventsHelper::isSelectionChanged( const uno::Sequence< uno::Any >& rAr uno::Any ScVbaEventsHelper::createWorksheet( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) const throw (lang::IllegalArgumentException, uno::RuntimeException) { - // Eventually we will be able to pull the Workbook/Worksheet objects - // directly from basic and register them as listeners - // extract sheet index, will throw, if parameter is invalid SCTAB nTab = lclGetTabFromArgs( rArgs, nIndex ); - - // create Workbook - uno::Sequence< uno::Any > aArgs( 2 ); - aArgs[ 0 ] <<= uno::Reference< uno::XInterface >(); - aArgs[ 1 ] <<= mxModel; - uno::Reference< uno::XInterface > xWorkbook( createVBAUnoAPIServiceWithArgs( mpShell, "ooo.vba.excel.Workbook", aArgs ), uno::UNO_SET_THROW ); - - // create WorkSheet - String aSheetName; - mpDoc->GetName( nTab, aSheetName ); - aArgs = uno::Sequence< uno::Any >( 3 ); - aArgs[ 0 ] <<= xWorkbook; - aArgs[ 1 ] <<= mxModel; - aArgs[ 2 ] <<= ::rtl::OUString( aSheetName ); - uno::Reference< uno::XInterface > xWorksheet( createVBAUnoAPIServiceWithArgs( mpShell, "ooo.vba.excel.Worksheet", aArgs ), uno::UNO_SET_THROW ); - return uno::Any( xWorksheet ); + return uno::Any( excel::getUnoSheetModuleObj( mxModel, nTab ) ); } uno::Any ScVbaEventsHelper::createRange( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) const @@ -723,11 +705,16 @@ uno::Any ScVbaEventsHelper::createRange( const uno::Sequence< uno::Any >& rArgs, throw lang::IllegalArgumentException(); uno::Sequence< uno::Any > aArgs( 2 ); - aArgs[ 0 ] <<= uno::Reference< uno::XInterface >(); // dummy parent if ( xRanges.is() ) + { + aArgs[ 0 ] <<= excel::getUnoSheetModuleObj( xRanges ); aArgs[ 1 ] <<= xRanges; + } else + { + aArgs[ 0 ] <<= excel::getUnoSheetModuleObj( xRange ); aArgs[ 1 ] <<= xRange; + } uno::Reference< uno::XInterface > xVbaRange( createVBAUnoAPIServiceWithArgs( mpShell, "ooo.vba.excel.Range", aArgs ), uno::UNO_SET_THROW ); return uno::Any( xVbaRange ); } @@ -735,9 +722,10 @@ uno::Any ScVbaEventsHelper::createRange( const uno::Sequence< uno::Any >& rArgs, uno::Any ScVbaEventsHelper::createHyperlink( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) const throw (lang::IllegalArgumentException, uno::RuntimeException) { + uno::Reference< table::XCell > xCell = getXSomethingFromArgs< table::XCell >( rArgs, nIndex, false ); uno::Sequence< uno::Any > aArgs( 2 ); - aArgs[ 0 ] <<= uno::Reference< uno::XInterface >(); // dummy parent - aArgs[ 1 ] <<= getXSomethingFromArgs< table::XCell >( rArgs, nIndex, false ); + aArgs[ 0 ] <<= excel::getUnoSheetModuleObj( xCell ); + aArgs[ 1 ] <<= xCell; uno::Reference< uno::XInterface > xHyperlink( createVBAUnoAPIServiceWithArgs( mpShell, "ooo.vba.excel.Hyperlink", aArgs ), uno::UNO_SET_THROW ); return uno::Any( xHyperlink ); } -- cgit From 3024512c90d8660d35d4824471c436d68aa62241 Mon Sep 17 00:00:00 2001 From: Niklas Nebel Date: Fri, 17 Sep 2010 19:32:15 +0200 Subject: mib19: #163664# text values for VBA range Value property must be parsed (always English) --- sc/source/ui/docshell/docfunc.cxx | 7 +++++- sc/source/ui/inc/docfunc.hxx | 3 ++- sc/source/ui/unoobj/cellsuno.cxx | 47 +++++++++++++++++++++++++++++++++++++++ sc/source/ui/vba/vbarange.cxx | 22 ++++++++++++++++-- 4 files changed, 75 insertions(+), 4 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index adbe26abf157..02dbc7546a38 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -986,7 +986,7 @@ ScTokenArray* lcl_ScDocFunc_CreateTokenArrayXML( const String& rText, const Stri ScBaseCell* ScDocFunc::InterpretEnglishString( const ScAddress& rPos, - const String& rText, const String& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar ) + const String& rText, const String& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar, short* pRetFormatType ) { ScDocument* pDoc = rDocShell.GetDocument(); ScBaseCell* pNewCell = NULL; @@ -1020,7 +1020,12 @@ ScBaseCell* ScDocFunc::InterpretEnglishString( const ScAddress& rPos, sal_uInt32 nEnglish = pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US); double fVal; if ( pFormatter->IsNumberFormat( rText, nEnglish, fVal ) ) + { pNewCell = new ScValueCell( fVal ); + // return the format type from the English format, so a localized format can be created + if ( pRetFormatType ) + *pRetFormatType = pFormatter->GetType( nEnglish ); + } else if ( rText.Len() ) pNewCell = ScBaseCell::CreateTextCell( rText, pDoc ); diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index c92cc082986d..e36e1a9af92f 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -92,7 +92,8 @@ public: // creates a new cell for use with PutCell ScBaseCell* InterpretEnglishString( const ScAddress& rPos, const String& rText, - const String& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar ); + const String& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar, + short* pRetFormatType = NULL ); bool ShowNote( const ScAddress& rPos, bool bShow = true ); inline bool HideNote( const ScAddress& rPos ) { return ShowNote( rPos, false ); } diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index ffef1a914a29..53ac57ee2318 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -6272,6 +6272,53 @@ void ScCellObj::SetFormulaWithGrammar( const ::rtl::OUString& rFormula, } } +void ScCellObj::InputEnglishString( const ::rtl::OUString& rText ) +{ + // This is like a mixture of setFormula and property FormulaLocal: + // The cell's number format is checked for "text", a new cell format may be set, + // but all parsing is in English. + + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + String aString(rText); + ScDocument* pDoc = pDocSh->GetDocument(); + SvNumberFormatter* pFormatter = pDoc->GetFormatTable(); + sal_uInt32 nOldFormat = pDoc->GetNumberFormat( aCellPos ); + if ( pFormatter->GetType( nOldFormat ) == NUMBERFORMAT_TEXT ) + { + SetString_Impl(aString, FALSE, FALSE); // text cell + } + else + { + ScDocFunc aFunc(*pDocSh); + short nFormatType = 0; + ScBaseCell* pNewCell = aFunc.InterpretEnglishString( aCellPos, aString, + EMPTY_STRING, formula::FormulaGrammar::GRAM_PODF_A1, &nFormatType ); + if (pNewCell) + { + if ( ( nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET ) == 0 && nFormatType != 0 ) + { + // apply a format for the recognized type and the old format's language + sal_uInt32 nNewFormat = ScGlobal::GetStandardFormat( *pFormatter, nOldFormat, nFormatType ); + if ( nNewFormat != nOldFormat ) + { + ScPatternAttr aPattern( pDoc->GetPool() ); + aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) ); + // ATTR_LANGUAGE_FORMAT remains unchanged + aFunc.ApplyAttributes( *GetMarkData(), aPattern, TRUE, TRUE ); + } + } + // put the cell into the document + // (after applying the format, so possible formula recalculation already uses the new format) + (void)aFunc.PutCell( aCellPos, pNewCell, TRUE ); + } + else + SetString_Impl(aString, FALSE, FALSE); // no cell from InterpretEnglishString, probably empty string + } + } +} + // XText uno::Reference SAL_CALL ScCellObj::createTextCursor() diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 891a5a36ecfd..5f97aaac506a 100755 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -740,8 +740,26 @@ CellValueSetter::processValue( const uno::Any& aValue, const uno::Reference< tab rtl::OUString aString; if ( aValue >>= aString ) { - uno::Reference< text::XTextRange > xTextRange( xCell, uno::UNO_QUERY_THROW ); - xTextRange->setString( aString ); + // The required behavior for a string value is: + // 1. If the first character is a single quote, use the rest as a string cell, regardless of the cell's number format. + // 2. Otherwise, if the cell's number format is "text", use the string value as a string cell. + // 3. Otherwise, parse the string value in English locale, and apply a corresponding number format with the cell's locale + // if the cell's number format was "General". + // Case 1 is handled here, the rest in ScCellObj::InputEnglishString + + if ( aString.toChar() == '\'' ) // case 1 - handle with XTextRange + { + rtl::OUString aRemainder( aString.copy(1) ); // strip the quote + uno::Reference< text::XTextRange > xTextRange( xCell, uno::UNO_QUERY_THROW ); + xTextRange->setString( aRemainder ); + } + else + { + // call implementation method InputEnglishString + ScCellObj* pCellObj = dynamic_cast< ScCellObj* >( xCell.get() ); + if ( pCellObj ) + pCellObj->InputEnglishString( aString ); + } } else isExtracted = false; -- cgit From eda40b701292c8bf568ea3359b2c4c0efaaa8333 Mon Sep 17 00:00:00 2001 From: "Daniel Rentz [dr]" Date: Mon, 20 Sep 2010 13:52:55 +0200 Subject: mib19: wrong parent in VBA Worksheet.Cells symbol --- sc/source/ui/vba/vbaworksheet.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx index aa7ee3932b08..7e033716a872 100644 --- a/sc/source/ui/vba/vbaworksheet.cxx +++ b/sc/source/ui/vba/vbaworksheet.cxx @@ -661,7 +661,7 @@ ScVbaWorksheet::Cells( const ::uno::Any &nRow, const ::uno::Any &nCol ) // Performance optimization for often-called Cells method: // Use a common helper method instead of creating a new ScVbaRange object uno::Reference< table::XCellRange > xRange( getSheet(), uno::UNO_QUERY_THROW ); - return ScVbaRange::CellsHelper( mxParent, mxContext, xRange, nRow, nCol ); + return ScVbaRange::CellsHelper( this, mxContext, xRange, nRow, nCol ); } uno::Reference< excel::XRange > -- cgit From 0f707f2b957e79db22d0ec138b8e58c9766d4da5 Mon Sep 17 00:00:00 2001 From: "Daniel Rentz [dr]" Date: Mon, 20 Sep 2010 13:53:57 +0200 Subject: mib19: #163666# fire Worksheet_Change event when using the Range.Value, Range.Formula, Range.Clear[Contents] symbols --- sc/source/ui/vba/vbaeventshelper.cxx | 54 ++++++++++++++++--------- sc/source/ui/vba/vbarange.cxx | 78 +++++++++++++++++++++++++----------- sc/source/ui/vba/vbarange.hxx | 18 ++++++--- 3 files changed, 102 insertions(+), 48 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx index b7438e87160e..6ea807a16eae 100755 --- a/sc/source/ui/vba/vbaeventshelper.cxx +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -59,7 +59,7 @@ using namespace ::ooo::vba; namespace { /** Extracts a sheet index from the specified element of the passed sequence. - The element may be an integer, or a Calc range or ranges object. */ + The element may be an integer, a Calc range or ranges object, or a VBA Range object. */ SCTAB lclGetTabFromArgs( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) throw (lang::IllegalArgumentException) { VbaEventsHelperBase::checkArgument( rArgs, nIndex ); @@ -69,12 +69,23 @@ SCTAB lclGetTabFromArgs( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nInde if( rArgs[ nIndex ] >>= nTab ) return nTab; - // next, try single range object + // try VBA Range object + uno::Reference< excel::XRange > xVbaRange = getXSomethingFromArgs< excel::XRange >( rArgs, nIndex ); + if( xVbaRange.is() ) + { + uno::Reference< XHelperInterface > xVbaHelper( xVbaRange, uno::UNO_QUERY_THROW ); + // TODO: in the future, the parent may be an excel::XChart (chart sheet) -> will there be a common base interface? + uno::Reference< excel::XWorksheet > xVbaSheet( xVbaHelper->getParent(), uno::UNO_QUERY_THROW ); + // VBA sheet index is 1-based + return static_cast< SCTAB >( xVbaSheet->getIndex() - 1 ); + } + + // try single UNO range object uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable = getXSomethingFromArgs< sheet::XCellRangeAddressable >( rArgs, nIndex ); if( xCellRangeAddressable.is() ) return xCellRangeAddressable->getRangeAddress().Sheet; - // at last, try range list + // at last, try UNO range list uno::Reference< sheet::XSheetCellRangeContainer > xRanges = getXSomethingFromArgs< sheet::XSheetCellRangeContainer >( rArgs, nIndex ); if( xRanges.is() ) { @@ -321,7 +332,7 @@ void SAL_CALL ScVbaEventsListener::changesOccurred( const util::ChangesEvent& aE aChange.ReplacedElement >>= xRangeObj; if( xRangeObj.is() ) { - uno::Sequence< uno::Any > aArgs(1); + uno::Sequence< uno::Any > aArgs( 1 ); aArgs[0] <<= xRangeObj; mrVbaEvents.processVbaEvent( WORKSHEET_CHANGE, aArgs ); } @@ -699,23 +710,28 @@ uno::Any ScVbaEventsHelper::createWorksheet( const uno::Sequence< uno::Any >& rA uno::Any ScVbaEventsHelper::createRange( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) const throw (lang::IllegalArgumentException, uno::RuntimeException) { - uno::Reference< sheet::XSheetCellRangeContainer > xRanges = getXSomethingFromArgs< sheet::XSheetCellRangeContainer >( rArgs, nIndex ); - uno::Reference< table::XCellRange > xRange = getXSomethingFromArgs< table::XCellRange >( rArgs, nIndex ); - if ( !xRanges.is() && !xRange.is() ) - throw lang::IllegalArgumentException(); - - uno::Sequence< uno::Any > aArgs( 2 ); - if ( xRanges.is() ) + // it is possible to pass an existing VBA Range object + uno::Reference< excel::XRange > xVbaRange = getXSomethingFromArgs< excel::XRange >( rArgs, nIndex ); + if( !xVbaRange.is() ) { - aArgs[ 0 ] <<= excel::getUnoSheetModuleObj( xRanges ); - aArgs[ 1 ] <<= xRanges; - } - else - { - aArgs[ 0 ] <<= excel::getUnoSheetModuleObj( xRange ); - aArgs[ 1 ] <<= xRange; + uno::Reference< sheet::XSheetCellRangeContainer > xRanges = getXSomethingFromArgs< sheet::XSheetCellRangeContainer >( rArgs, nIndex ); + uno::Reference< table::XCellRange > xRange = getXSomethingFromArgs< table::XCellRange >( rArgs, nIndex ); + if ( !xRanges.is() && !xRange.is() ) + throw lang::IllegalArgumentException(); + + uno::Sequence< uno::Any > aArgs( 2 ); + if ( xRanges.is() ) + { + aArgs[ 0 ] <<= excel::getUnoSheetModuleObj( xRanges ); + aArgs[ 1 ] <<= xRanges; + } + else + { + aArgs[ 0 ] <<= excel::getUnoSheetModuleObj( xRange ); + aArgs[ 1 ] <<= xRange; + } + xVbaRange.set( createVBAUnoAPIServiceWithArgs( mpShell, "ooo.vba.excel.Range", aArgs ), uno::UNO_QUERY_THROW ); } - uno::Reference< uno::XInterface > xVbaRange( createVBAUnoAPIServiceWithArgs( mpShell, "ooo.vba.excel.Range", aArgs ), uno::UNO_SET_THROW ); return uno::Any( xVbaRange ); } diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 5f97aaac506a..6cd129a6ae2d 100755 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -24,6 +24,9 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + +#include "vbarange.hxx" + #include #include @@ -31,6 +34,8 @@ #include #include +#include +#include #include #include #include @@ -135,7 +140,7 @@ #include #include -#include "vbarange.hxx" +#include "vbaapplication.hxx" #include "vbafont.hxx" #include "vbacomment.hxx" #include "vbainterior.hxx" @@ -268,6 +273,26 @@ SfxItemSet* ScVbaRange::getCurrentDataSet( ) throw ( uno::RuntimeException ) return pDataSet; } +void ScVbaRange::fireChangeEvent() +{ + if( ScVbaApplication::getDocumentEventsEnabled() ) + { + if( ScDocument* pDoc = getScDocument() ) + { + uno::Reference< script::vba::XVBAEventProcessor > xVBAEvents = pDoc->GetVbaEventProcessor(); + if( xVBAEvents.is() ) try + { + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[ 0 ] <<= uno::Reference< excel::XRange >( this ); + xVBAEvents->processVbaEvent( script::vba::VBAEventId::WORKSHEET_CHANGE, aArgs ); + } + catch( uno::Exception& ) + { + } + } + } +} + class SingleRangeEnumeration : public EnumerationHelper_BASE { uno::Reference< XHelperInterface > m_xParent; @@ -1498,7 +1523,7 @@ ScVbaRange::getValue() throw (uno::RuntimeException) void -ScVbaRange::setValue( const uno::Any &aValue, ValueSetter& valueSetter ) throw (uno::RuntimeException) +ScVbaRange::setValue( const uno::Any& aValue, ValueSetter& valueSetter, bool bFireEvent ) throw (uno::RuntimeException) { uno::TypeClass aClass = aValue.getValueTypeClass(); if ( aClass == uno::TypeClass_SEQUENCE ) @@ -1533,6 +1558,7 @@ ScVbaRange::setValue( const uno::Any &aValue, ValueSetter& valueSetter ) thro { visitArray( valueSetter ); } + if( bFireEvent ) fireChangeEvent(); } void SAL_CALL @@ -1547,20 +1573,20 @@ ScVbaRange::setValue( const uno::Any &aValue ) throw (uno::RuntimeException) return; } CellValueSetter valueSetter( aValue ); - setValue( aValue, valueSetter ); + setValue( aValue, valueSetter, true ); } -void +void SAL_CALL ScVbaRange::Clear() throw (uno::RuntimeException) { using namespace ::com::sun::star::sheet::CellFlags; sal_Int32 nFlags = VALUE | DATETIME | STRING | FORMULA | HARDATTR | EDITATTR | FORMATTED; - ClearContents( nFlags ); + ClearContents( nFlags, true ); } //helper ClearContent void -ScVbaRange::ClearContents( sal_Int32 nFlags ) throw (uno::RuntimeException) +ScVbaRange::ClearContents( sal_Int32 nFlags, bool bFireEvent ) throw (uno::RuntimeException) { // #TODO code within the test below "if ( m_Areas.... " can be removed // Test is performed only because m_xRange is NOT set to be @@ -1574,40 +1600,44 @@ ScVbaRange::ClearContents( sal_Int32 nFlags ) throw (uno::RuntimeException) uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); ScVbaRange* pRange = getImplementation( xRange ); if ( pRange ) - pRange->ClearContents( nFlags ); + pRange->ClearContents( nFlags, false ); // do not fire for single ranges } + // fire change event for the entire range list + if( bFireEvent ) fireChangeEvent(); return; } uno::Reference< sheet::XSheetOperation > xSheetOperation(mxRange, uno::UNO_QUERY_THROW); xSheetOperation->clearContents( nFlags ); + if( bFireEvent ) fireChangeEvent(); } -void + +void SAL_CALL ScVbaRange::ClearComments() throw (uno::RuntimeException) { - ClearContents( sheet::CellFlags::ANNOTATION ); + ClearContents( sheet::CellFlags::ANNOTATION, false ); } -void +void SAL_CALL ScVbaRange::ClearContents() throw (uno::RuntimeException) { - sal_Int32 nClearFlags = ( sheet::CellFlags::VALUE | - sheet::CellFlags::STRING | sheet::CellFlags::DATETIME | - sheet::CellFlags::FORMULA ); - ClearContents( nClearFlags ); + using namespace ::com::sun::star::sheet::CellFlags; + sal_Int32 nFlags = VALUE | STRING | DATETIME | FORMULA; + ClearContents( nFlags, true ); } -void +void SAL_CALL ScVbaRange::ClearFormats() throw (uno::RuntimeException) { - //FIXME: need to check if we need to combine sheet::CellFlags::FORMATTED - sal_Int32 nClearFlags = sheet::CellFlags::HARDATTR | sheet::CellFlags::FORMATTED | sheet::CellFlags::EDITATTR; - ClearContents( nClearFlags ); + //FIXME: need to check if we need to combine FORMATTED + using namespace ::com::sun::star::sheet::CellFlags; + sal_Int32 nFlags = HARDATTR | FORMATTED | EDITATTR; + ClearContents( nFlags, false ); } void -ScVbaRange::setFormulaValue( const uno::Any& rFormula, formula::FormulaGrammar::Grammar eGram ) throw (uno::RuntimeException) +ScVbaRange::setFormulaValue( const uno::Any& rFormula, formula::FormulaGrammar::Grammar eGram, bool bFireEvent ) throw (uno::RuntimeException) { // If this is a multiple selection apply setFormula over all areas if ( m_Areas->getCount() > 1 ) @@ -1618,7 +1648,7 @@ ScVbaRange::setFormulaValue( const uno::Any& rFormula, formula::FormulaGrammar:: return; } CellFormulaValueSetter formulaValueSetter( rFormula, getScDocument(), eGram ); - setValue( rFormula, formulaValueSetter ); + setValue( rFormula, formulaValueSetter, bFireEvent ); } uno::Any @@ -1642,7 +1672,7 @@ void ScVbaRange::setFormula(const uno::Any &rFormula ) throw (uno::RuntimeException) { // #FIXME converting "=$a$1" e.g. CONV_XL_A1 -> CONV_OOO // results in "=$a$1:a1", temporalily disable conversion - setFormulaValue( rFormula,formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );; + setFormulaValue( rFormula,formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true ); } uno::Any @@ -1654,7 +1684,7 @@ ScVbaRange::getFormulaR1C1() throw (::com::sun::star::uno::RuntimeException) void ScVbaRange::setFormulaR1C1(const uno::Any& rFormula ) throw (uno::RuntimeException) { - setFormulaValue( rFormula,formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 ); + setFormulaValue( rFormula,formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true ); } uno::Any @@ -3273,7 +3303,7 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any& throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("That command cannot be used on multiple selections" ) ), uno::Reference< uno::XInterface >() ); sal_Int16 nDataOption1 = excel::XlSortDataOption::xlSortNormal; - sal_Int16 nDataOption2 = excel::XlSortDataOption::xlSortNormal;; + sal_Int16 nDataOption2 = excel::XlSortDataOption::xlSortNormal; sal_Int16 nDataOption3 = excel::XlSortDataOption::xlSortNormal; ScDocument* pDoc = getScDocument(); @@ -4428,7 +4458,7 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const // Use the normal uno api, sometimes e.g. when you want to use ALL as the filter // we can't use refresh as the uno interface doesn't have a concept of ALL // in this case we just call the core calc functionality - - bool bAll = false;; + bool bAll = false; if ( ( Field >>= nField ) ) { uno::Reference< sheet::XSheetFilterDescriptor2 > xDesc( diff --git a/sc/source/ui/vba/vbarange.hxx b/sc/source/ui/vba/vbarange.hxx index a8aada649575..e8079a855544 100644 --- a/sc/source/ui/vba/vbarange.hxx +++ b/sc/source/ui/vba/vbarange.hxx @@ -99,6 +99,7 @@ class ScVbaRange : public ScVbaRange_BASE sal_Bool mbIsRows; sal_Bool mbIsColumns; css::uno::Reference< ov::excel::XValidation > m_xValidation; + double getCalcColWidth( const css::table::CellRangeAddress& ) throw (css::uno::RuntimeException); double getCalcRowHeight( const css::table::CellRangeAddress& ) throw (css::uno::RuntimeException); void visitArray( ArrayVisitor& vistor ); @@ -107,11 +108,14 @@ class ScVbaRange : public ScVbaRange_BASE void fillSeries( css::sheet::FillDirection nFillDirection, css::sheet::FillMode nFillMode, css::sheet::FillDateMode nFillDateMode, double fStep, double fEndValue ) throw( css::uno::RuntimeException ); - void ClearContents( sal_Int32 nFlags ) throw (css::uno::RuntimeException); - virtual void setValue( const css::uno::Any& aValue, ValueSetter& setter) throw ( css::uno::RuntimeException); - virtual css::uno::Any getValue( ValueGetter& rValueGetter ) throw (css::uno::RuntimeException); - virtual css::uno::Any getFormulaValue( formula::FormulaGrammar::Grammar ) throw (css::uno::RuntimeException); - virtual void setFormulaValue( const css::uno::Any& aValue, formula::FormulaGrammar::Grammar ) throw ( css::uno::RuntimeException); + void ClearContents( sal_Int32 nFlags, bool bFireEvent ) throw (css::uno::RuntimeException); + + css::uno::Any getValue( ValueGetter& rValueGetter ) throw (css::uno::RuntimeException); + void setValue( const css::uno::Any& aValue, ValueSetter& setter, bool bFireEvent ) throw ( css::uno::RuntimeException); + + css::uno::Any getFormulaValue( formula::FormulaGrammar::Grammar ) throw (css::uno::RuntimeException); + void setFormulaValue( const css::uno::Any& aValue, formula::FormulaGrammar::Grammar, bool bFireEvent ) throw ( css::uno::RuntimeException); + css::uno::Reference< ov::excel::XRange > getArea( sal_Int32 nIndex ) throw( css::uno::RuntimeException ); ScCellRangeObj* getCellRangeObj( ) throw ( css::uno::RuntimeException ); ScCellRangesObj* getCellRangesObj() throw ( css::uno::RuntimeException ); @@ -120,6 +124,10 @@ class ScVbaRange : public ScVbaRange_BASE css::uno::Reference< ov::excel::XRange > PreviousNext( bool bIsPrevious ); css::uno::Reference< ov::excel::XRange > SpecialCellsImpl( sal_Int32 nType, const css::uno::Any& _oValue) throw ( css::script::BasicErrorException ); css::awt::Point getPosition() throw ( css::uno::RuntimeException ); + + /** Fires a Worksheet_Change event for this range or range list. */ + void fireChangeEvent(); + protected: virtual ScCellRangesBase* getCellRangesBase() throw ( css::uno::RuntimeException ); virtual SfxItemSet* getCurrentDataSet( ) throw ( css::uno::RuntimeException ); -- cgit From 011d4319b1bf4082cec40482df7251d5e550aae2 Mon Sep 17 00:00:00 2001 From: "Daniel Rentz [dr]" Date: Mon, 20 Sep 2010 15:32:20 +0200 Subject: mib19: #163691# remember VBA object provider instance --- sc/source/ui/unoobj/docuno.cxx | 2 ++ sc/source/ui/vba/vbaworksheet.cxx | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 89193ad8ddf0..9682d1a3a02a 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -1958,6 +1958,7 @@ uno::Reference SAL_CALL ScModelObj::createInstance( case SC_SERVICE_MARKERTAB: xRet.set(xDrawMarkerTab); break; case SC_SERVICE_DASHTAB: xRet.set(xDrawDashTab); break; case SC_SERVICE_CHDATAPROV: xRet.set(xChartDataProv); break; + case SC_SERVICE_VBAOBJECTPROVIDER: xRet.set(xObjProvider); break; } // #i64497# If a chart is in a temporary document during clipoard paste, @@ -1983,6 +1984,7 @@ uno::Reference SAL_CALL ScModelObj::createInstance( case SC_SERVICE_MARKERTAB: xDrawMarkerTab.set(xRet); break; case SC_SERVICE_DASHTAB: xDrawDashTab.set(xRet); break; case SC_SERVICE_CHDATAPROV: xChartDataProv.set(xRet); break; + case SC_SERVICE_VBAOBJECTPROVIDER: xObjProvider.set(xRet); break; } } } diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx index 7e033716a872..6491024071b2 100644 --- a/sc/source/ui/vba/vbaworksheet.cxx +++ b/sc/source/ui/vba/vbaworksheet.cxx @@ -195,7 +195,7 @@ ScVbaWorksheet::ScVbaWorksheet(const uno::Reference< XHelperInterface >& xParent ScVbaWorksheet::ScVbaWorksheet( uno::Sequence< uno::Any> const & args, uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) : WorksheetImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), mxModel( getXSomethingFromArgs< frame::XModel >( args, 1 ) ), mbVeryHidden( false ) { - if ( args.getLength() < 2 ) + if ( args.getLength() < 3 ) throw lang::IllegalArgumentException(); rtl::OUString sSheetName; -- cgit From edd423387c36fa561dc34ccc43097aac58813a9a Mon Sep 17 00:00:00 2001 From: "Daniel Rentz [dr]" Date: Mon, 20 Sep 2010 20:50:44 +0200 Subject: mib19: #163655# do not fire events when document is disposed --- sc/source/ui/docshell/docsh.cxx | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 9e98d7430d96..e7089349fdb7 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -553,6 +553,13 @@ void __EXPORT ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) xVbaEvents->processVbaEvent( WORKBOOK_AFTERSAVE, aArgs ); } break; + case SFX_EVENT_CLOSEDOC: + { + // #163655# prevent event processing after model is disposed + aDocument.SetVbaEventProcessor( uno::Reference< script::vba::XVBAEventProcessor >() ); + uno::Reference< lang::XEventListener >( xVbaEvents, uno::UNO_QUERY_THROW )->disposing( lang::EventObject() ); + } + break; } } } @@ -618,19 +625,6 @@ void __EXPORT ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) SetReadOnlyUI( sal_True ); } } - - // VBA specific initialization - if( aDocument.IsInVBAMode() ) try - { - uno::Reference< frame::XModel > xModel( GetModel(), uno::UNO_SET_THROW ); - - // create VBAGlobals object if not yet done (this also creates the "ThisExcelDoc" symbol and the event processor) - uno::Reference< lang::XMultiServiceFactory > xFactory( xModel, uno::UNO_QUERY_THROW ); - xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAGlobals" ) ) ); - } - catch( uno::Exception& ) - { - } } break; case SFX_EVENT_VIEWCREATED: -- cgit