[ooo-build-commit] patches/dev300 patches/vba

Noel Power noelp at kemper.freedesktop.org
Thu Jun 18 03:03:44 PDT 2009


 patches/dev300/apply                                 |    2 
 patches/vba/vba-fallback-to-calling-doc-context.diff |  720 +++++++++++++++++++
 2 files changed, 722 insertions(+)

New commits:
commit 35f0d0d83ce2f39626c1a8594bb65163102ef677
Author: Noel Power <noel.power at novell.com>
Date:   Thu Jun 18 12:01:22 2009 +0100

    hack to fallback to the calling document ( as active doc ) when none other
    
    * patches/dev300/apply:  add new patch
    * patches/vba/vba-fallback-to-calling-doc-context.diff: ensure that we always find  a value for document for current doc ( e.g. if a document doesn't appear to be active ( in a windowing sense ) then we should fall back to ourselves

diff --git a/patches/dev300/apply b/patches/dev300/apply
index 6d163f9..57eaafe 100644
--- a/patches/dev300/apply
+++ b/patches/dev300/apply
@@ -1838,6 +1838,8 @@ vba-menubar-objects.diff, n#508113, Fong
 vba-fix-missing-codename.diff, n#507768
 # fix zoom, should only affect active sheet
 vba-zoom-per-sheet.diff
+# fall back to doc context for active sheet if it fails
+vba-fallback-to-calling-doc-context.diff
 [VBAUntested]
 SectionOwner => noelpwer
 # doesn't work
diff --git a/patches/vba/vba-fallback-to-calling-doc-context.diff b/patches/vba/vba-fallback-to-calling-doc-context.diff
new file mode 100644
index 0000000..b359f7d
--- /dev/null
+++ b/patches/vba/vba-fallback-to-calling-doc-context.diff
@@ -0,0 +1,720 @@
+diff --git sc/source/filter/excel/excimp8.cxx sc/source/filter/excel/excimp8.cxx
+index 4d1db8b..e064e41 100644
+--- sc/source/filter/excel/excimp8.cxx
++++ sc/source/filter/excel/excimp8.cxx
+@@ -276,7 +276,9 @@ void ImportExcel8::ReadBasic( void )
+         if( bLoadCode || bLoadStrg )
+         {
+             uno::Any aGlobs;
+-            aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString::createFromAscii( "ooo.vba.excel.Globals") );
++            uno::Sequence< uno::Any > aArgs(1);
++            aArgs[ 0 ] <<= pShell->GetModel();
++            aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( ::rtl::OUString::createFromAscii( "ooo.vba.excel.Globals"), aArgs );
+             pShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", aGlobs );
+             SvxImportMSVBasic aBasicImport( *pShell, *xRootStrg, bLoadCode, bLoadStrg );
+ 	    bool bAsComment = !bLoadExecutable || !aGlobs.hasValue();
+diff --git sc/source/ui/vba/excelvbahelper.cxx sc/source/ui/vba/excelvbahelper.cxx
+index 5f133d9..d4f8967 100644
+--- sc/source/ui/vba/excelvbahelper.cxx
++++ sc/source/ui/vba/excelvbahelper.cxx
+@@ -107,10 +107,10 @@ public:
+ };
+ 
+ void
+-implnPaste()
++implnPaste( const uno::Reference< frame::XModel>& xModel )
+ {
+ 	PasteCellsWarningReseter resetWarningBox;
+-	ScTabViewShell* pViewShell = getCurrentBestViewShell();
++	ScTabViewShell* pViewShell = getBestViewShell( xModel );
+ 	if ( pViewShell )
+ 	{
+ 		pViewShell->PasteFromSystem();
+@@ -120,31 +120,28 @@ implnPaste()
+ 
+ 
+ void
+-implnCopy()
++implnCopy( const uno::Reference< frame::XModel>& xModel )
+ {
+-	ScTabViewShell* pViewShell = getCurrentBestViewShell();
++	ScTabViewShell* pViewShell = getBestViewShell( xModel );
+ 	if ( pViewShell )
+ 		pViewShell->CopyToClip(NULL,false,false,true);
+ }
+ 
+ void 
+-implnCut()
++implnCut( const uno::Reference< frame::XModel>& xModel )
+ {
+-	ScTabViewShell* pViewShell =  getCurrentBestViewShell();
++	ScTabViewShell* pViewShell =  getBestViewShell( xModel );
+ 	if ( pViewShell )
+ 		pViewShell->CutToClip( NULL, TRUE );
+ }
+ 
+-void implnPasteSpecial(USHORT nFlags,USHORT nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose)
++void implnPasteSpecial( const uno::Reference< frame::XModel>& xModel, USHORT nFlags,USHORT nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose)
+ {
+ 	PasteCellsWarningReseter resetWarningBox;
+ 	sal_Bool bAsLink(sal_False), bOtherDoc(sal_False);
+ 	InsCellCmd eMoveMode = INS_NONE;
+ 
+-	ScTabViewShell* pTabViewShell = ScTabViewShell::GetActiveViewShell();
+-	if ( !pTabViewShell ) 
+-		// none active, try next best
+-		pTabViewShell = getCurrentBestViewShell();
++	ScTabViewShell* pTabViewShell = getBestViewShell( xModel );
+ 	if ( pTabViewShell )
+ 	{
+ 		ScViewData* pView = pTabViewShell->GetViewData();	
+@@ -191,16 +188,16 @@ getBestViewShell( const css::uno::Reference< css::frame::XModel>& xModel )
+ }
+ 
+ ScTabViewShell* 
+-getCurrentBestViewShell()
++getCurrentBestViewShell(  const uno::Reference< uno::XComponentContext >& xContext )
+ { 
+-	uno::Reference< frame::XModel > xModel = getCurrentExcelDoc();
++	uno::Reference< frame::XModel > xModel = getCurrentExcelDoc( xContext );
+ 	return getBestViewShell( xModel );
+ }
+ 
+ SfxViewFrame* 
+-getCurrentViewFrame()
++getViewFrame( const uno::Reference< frame::XModel >& xModel )
+ {
+-	ScTabViewShell* pViewShell = getCurrentBestViewShell();	
++	ScTabViewShell* pViewShell = getBestViewShell( xModel );	
+ 	if ( pViewShell )
+ 		return pViewShell->GetViewFrame();
+ 	return NULL;
+diff --git sc/source/ui/vba/excelvbahelper.hxx sc/source/ui/vba/excelvbahelper.hxx
+index 3a3b7f8..8c7c430 100644
+--- sc/source/ui/vba/excelvbahelper.hxx
++++ sc/source/ui/vba/excelvbahelper.hxx
+@@ -41,15 +41,15 @@ namespace ooo
+ 	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();
+-		void implnPaste();
+-		void implnCut();
+-		void implnPasteSpecial(sal_uInt16 nFlags,sal_uInt16 nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose);
++		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();
+-		SfxViewFrame* getCurrentViewFrame();
++		ScTabViewShell* getCurrentBestViewShell( const css::uno::Reference< css::uno::XComponentContext >& xContext );
++		SfxViewFrame* getViewFrame( const css::uno::Reference< css::frame::XModel >& xModel );
+             class ScVbaCellRangeAccess
+             {
+             public:
+diff --git sc/source/ui/vba/vbaapplication.cxx sc/source/ui/vba/vbaapplication.cxx
+index 68d0834..68dff2f 100644
+--- sc/source/ui/vba/vbaapplication.cxx
++++ sc/source/ui/vba/vbaapplication.cxx
+@@ -125,7 +125,7 @@ class ActiveWorkbook : public ScVbaWorkbook
+ protected:
+ 	virtual uno::Reference< frame::XModel > getModel()
+ 	{ 	
+-		return getCurrentExcelDoc(); 
++		return getCurrentExcelDoc(mxContext); 
+ 	}
+ public:
+ 	ActiveWorkbook( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext) : ScVbaWorkbook(  xParent, xContext ){}
+@@ -230,7 +230,7 @@ ScVbaApplication::getActiveCell() throw (uno::RuntimeException )
+ {
+ 	uno::Reference< sheet::XSpreadsheetView > xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW );
+ 	uno::Reference< table::XCellRange > xRange( xView->getActiveSheet(), ::uno::UNO_QUERY_THROW);
+-	ScTabViewShell* pViewShell = excel::getCurrentBestViewShell();
++	ScTabViewShell* pViewShell = excel::getCurrentBestViewShell(mxContext);
+ 	if ( !pViewShell )
+ 		throw uno::RuntimeException( rtl::OUString::createFromAscii("No ViewShell available"), uno::Reference< uno::XInterface >() );
+ 	ScViewData* pTabView = pViewShell->GetViewData();
+@@ -509,7 +509,7 @@ ScVbaApplication::GoTo( const uno::Any& Reference, const uno::Any& Scroll ) thro
+                 xModel->getCurrentController(), uno::UNO_QUERY_THROW );
+         uno::Reference< sheet::XSpreadsheet > xDoc = xSpreadsheet->getActiveSheet();
+ 
+-        ScTabViewShell* pShell = excel::getCurrentBestViewShell();
++        ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
+         ScGridWindow* gridWindow = (ScGridWindow*)pShell->GetWindow(); 
+         try
+         {
+@@ -551,7 +551,7 @@ ScVbaApplication::GoTo( const uno::Any& Reference, const uno::Any& Scroll ) thro
+     if( Reference >>= xRange )
+     {
+         uno::Reference< excel::XRange > xVbaRange( Reference, uno::UNO_QUERY );
+-        ScTabViewShell* pShell = excel::getCurrentBestViewShell();
++        ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
+         ScGridWindow* gridWindow = (ScGridWindow*)pShell->GetWindow(); 
+         if ( xVbaRange.is() )
+         {
+@@ -1135,7 +1135,7 @@ ScVbaApplication::Volatile( const uno::Any& aVolatile )  throw ( uno::RuntimeExc
+ ScVbaApplication::getDisplayFormulaBar() throw ( css::uno::RuntimeException )
+ {
+ 	sal_Bool bRes = sal_False;
+-	ScTabViewShell* pViewShell = excel::getCurrentBestViewShell();
++	ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext );
+ 	if ( pViewShell )
+ 	{
+ 		SfxBoolItem sfxFormBar( FID_TOGGLEINPUTLINE);
+@@ -1153,7 +1153,7 @@ ScVbaApplication::getDisplayFormulaBar() throw ( css::uno::RuntimeException )
+ void SAL_CALL 
+ ScVbaApplication::setDisplayFormulaBar( ::sal_Bool _displayformulabar ) throw ( css::uno::RuntimeException )
+ {
+-	ScTabViewShell* pViewShell = excel::getCurrentBestViewShell();
++	ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext );
+ 	if ( pViewShell && ( _displayformulabar !=  getDisplayFormulaBar() ) )
+ 	{
+ 		SfxBoolItem sfxFormBar( FID_TOGGLEINPUTLINE, _displayformulabar);
+@@ -1185,7 +1185,7 @@ ScVbaApplication::Caller( const uno::Any& /*aIndex*/ ) throw ( uno::RuntimeExcep
+ uno::Reference< frame::XModel > 
+ ScVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException)
+ {
+-    return getCurrentExcelDoc();
++    return getCurrentExcelDoc(mxContext);
+ }
+ 
+ uno::Any SAL_CALL
+diff --git sc/source/ui/vba/vbachartobject.cxx sc/source/ui/vba/vbachartobject.cxx
+index 71942f1..2a2899e 100644
+--- sc/source/ui/vba/vbachartobject.cxx
++++ sc/source/ui/vba/vbachartobject.cxx
+@@ -124,7 +124,7 @@ ScVbaChartObject::Activate() throw ( script::BasicErrorException )
+ 		// fact probably the chart object should be created with 
+ 		// the XModel owner
+ 		//uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getXModel().getCurrentController());
+-		uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getCurrentExcelDoc()->getCurrentController(), uno::UNO_QUERY_THROW );
++		uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getCurrentExcelDoc(mxContext)->getCurrentController(), uno::UNO_QUERY_THROW );
+ 		xSelectionSupplier->select(uno::makeAny(xShape));
+ 	}
+ 	catch (uno::Exception& )
+diff --git sc/source/ui/vba/vbaglobals.cxx sc/source/ui/vba/vbaglobals.cxx
+index ac5e4f5..6181cf0 100644
+--- sc/source/ui/vba/vbaglobals.cxx
++++ sc/source/ui/vba/vbaglobals.cxx
+@@ -50,10 +50,20 @@ using namespace ::ooo::vba;
+ // ScVbaGlobals
+ // =============================================================================
+ 
+-ScVbaGlobals::ScVbaGlobals(  css::uno::Reference< css::uno::XComponentContext >const& rxContext ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext )
++//ScVbaGlobals::ScVbaGlobals(  css::uno::Reference< css::uno::XComponentContext >const& rxContext,  ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext )
++rtl::OUString sDocCtxName( RTL_CONSTASCII_USTRINGPARAM("ExcelDocumentContext") );
++
++ScVbaGlobals::ScVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, sDocCtxName )
+ {
+ 	OSL_TRACE("ScVbaGlobals::ScVbaGlobals()");
+-        init( rxContext, uno::Any( getApplication() ) );
++
++        uno::Sequence< beans::PropertyValue > aInitArgs( 2 );
++        aInitArgs[ 0 ].Name = rtl::OUString::createFromAscii("Application");
++        aInitArgs[ 0 ].Value = uno::makeAny( getApplication() );
++        aInitArgs[ 1 ].Name = sDocCtxName;
++        aInitArgs[ 1 ].Value = uno::makeAny( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ) );
++        
++        init( aInitArgs );
+ }
+ 
+ ScVbaGlobals::~ScVbaGlobals()
+@@ -68,8 +78,9 @@ uno::Reference<excel::XApplication >
+ ScVbaGlobals::getApplication() throw (uno::RuntimeException)
+ {
+ //	OSL_TRACE("In ScVbaGlobals::getApplication");	
+-	static  uno::Reference< excel::XApplication > ExcelApplication( new ScVbaApplication( mxContext) );
+-   	return ExcelApplication; 
++        if ( !mxApplication.is() )
++	    mxApplication.set( new ScVbaApplication( mxContext) );
++   	return mxApplication; 
+ }
+ 
+ uno::Reference< excel::XWorkbook > SAL_CALL 
+@@ -264,7 +275,7 @@ ScVbaGlobals::getServiceNames()
+ namespace globals
+ {
+ namespace sdecl = comphelper::service_decl;
+-sdecl::vba_service_class_<ScVbaGlobals, sdecl::with_args<false> > serviceImpl;
++sdecl::vba_service_class_<ScVbaGlobals, sdecl::with_args<true> > serviceImpl;
+ extern sdecl::ServiceDecl const serviceDecl(
+     serviceImpl,
+     "ScVbaGlobals",
+diff --git sc/source/ui/vba/vbaglobals.hxx sc/source/ui/vba/vbaglobals.hxx
+index 66dd1fa..53838b9 100644
+--- sc/source/ui/vba/vbaglobals.hxx
++++ sc/source/ui/vba/vbaglobals.hxx
+@@ -48,13 +48,16 @@ typedef ::cppu::ImplInheritanceHelper1< VbaGlobalsBase, ov::excel::XGlobals > Sc
+ 
+     class ScVbaGlobals : public ScVbaGlobals_BASE
+     {
++        css::uno::Reference< ov::excel::XApplication > mxApplication;
+         virtual css::uno::Reference<
+  ov::excel::XApplication > SAL_CALL getApplication()
+                         throw (css::uno::RuntimeException);
+     public:
+ 	
+-        ScVbaGlobals(
++        ScVbaGlobals( css::uno::Sequence< css::uno::Any > const& aArgs,
+             css::uno::Reference< css::uno::XComponentContext >const& rxContext );
++        //ScVbaGlobals(
++        //    css::uno::Reference< css::uno::XComponentContext >const& rxContext,  );
+         virtual ~ScVbaGlobals();
+ 
+         // XGlobals
+diff --git sc/source/ui/vba/vbarange.cxx sc/source/ui/vba/vbarange.cxx
+index 4512c46..a3907a7 100644
+--- sc/source/ui/vba/vbarange.cxx
++++ sc/source/ui/vba/vbarange.cxx
+@@ -1996,9 +1996,9 @@ bool cellInRange( const table::CellRangeAddress& rAddr, const sal_Int32& nCol, c
+ 	return false;
+ }
+ 
+-void setCursor(  const SCCOL& nCol, const SCROW& nRow, bool bInSel = true )
++void setCursor(  const SCCOL& nCol, const SCROW& nRow, const uno::Reference< frame::XModel >& xModel,  bool bInSel = true )
+ {
+-	ScTabViewShell* pShell = excel::getCurrentBestViewShell();
++	ScTabViewShell* pShell = excel::getBestViewShell( xModel );
+ 	if ( pShell )
+ 	{
+ 		if ( bInSel )
+@@ -2045,7 +2045,7 @@ ScVbaRange::Activate() throw (uno::RuntimeException)
+ 		{
+ 			if ( cellInRange( nAddrs[index], thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
+ 			{
+-				setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ) );
++				setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
+ 				return;
+ 			}
+ 			
+@@ -2053,7 +2053,7 @@ ScVbaRange::Activate() throw (uno::RuntimeException)
+ 	}	
+ 
+ 	if ( xRange.is() && cellInRange( xRange->getRangeAddress(), thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
+-		setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ) );
++		setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
+ 	else
+ 	{
+ 		// if this range is multi cell select the range other
+@@ -2061,7 +2061,7 @@ ScVbaRange::Activate() throw (uno::RuntimeException)
+ 		if ( isSingleCellRange() ) 
+ 			// This top-leftmost cell of this Range is not in the current
+ 			// selection so just select this range
+-			setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), false  );
++			setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel, false  );
+ 		else
+ 			Select();
+ 	}
+@@ -2216,8 +2216,9 @@ ScVbaRange::Copy(const ::uno::Any& Destination) throw (uno::RuntimeException)
+ 	}
+ 	else
+ 	{
++		uno::Reference< frame::XModel > xModel = getModelFromRange( mxRange );
+ 		Select();
+-		excel::implnCopy();
++		excel::implnCopy( xModel );
+ 	}
+ }
+ 
+@@ -2240,8 +2241,9 @@ ScVbaRange::Cut(const ::uno::Any& Destination) throw (uno::RuntimeException)
+ 		xMover->moveRange( xDestination->getCellAddress(), xSource->getRangeAddress() );
+ 	}
+ 	{
++		uno::Reference< frame::XModel > xModel = getModelFromRange( mxRange );
+ 		Select();
+-		excel::implnCut();
++		excel::implnCut( xModel );
+ 	}
+ }
+                                                                                                                              
+@@ -2574,7 +2576,7 @@ ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, cons
+ 
+ 	USHORT nFlags = getPasteFlags(nPaste);
+ 	USHORT nFormulaBits = getPasteFormulaBits(nOperation);
+-	excel::implnPasteSpecial(nFlags,nFormulaBits,bSkipBlanks,bTranspose);
++	excel::implnPasteSpecial(pShell->GetModel(), nFlags,nFormulaBits,bSkipBlanks,bTranspose);
+ 	// restore selection
+ 	xSelection->select( uno::makeAny( xSel ) );
+ }
+@@ -3249,7 +3251,9 @@ ScVbaRange::End( ::sal_Int32 Direction )  throw (uno::RuntimeException)
+ 	// position current cell upper left of this range
+ 	Cells( uno::makeAny( (sal_Int32) 1 ), uno::makeAny( (sal_Int32) 1 ) )->Select();
+ 
+-	SfxViewFrame* pViewFrame = excel::getCurrentViewFrame();
++        uno::Reference< frame::XModel > xModel = getModelFromRange( mxRange );
++
++	SfxViewFrame* pViewFrame = excel::getViewFrame( xModel );
+ 	if ( pViewFrame )
+ 	{
+ 		SfxAllItemSet aArgs( SFX_APP()->GetPool() );
+@@ -3893,7 +3897,7 @@ ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xC
+ 	if ( Cell1.hasValue() && !Cell2.hasValue() && sRangeName.getLength() )
+ 	{
+ 		const static rtl::OUString sNamedRanges( RTL_CONSTASCII_USTRINGPARAM("NamedRanges"));
+-		uno::Reference< beans::XPropertySet > xPropSet( getCurrentExcelDoc(), uno::UNO_QUERY_THROW );
++		uno::Reference< beans::XPropertySet > xPropSet( getCurrentExcelDoc(xContext), uno::UNO_QUERY_THROW );
+ 		
+ 		uno::Reference< container::XNameAccess > xNamed( xPropSet->getPropertyValue( sNamedRanges ), uno::UNO_QUERY_THROW );
+ 		uno::Reference< sheet::XCellRangeReferrer > xReferrer;
+@@ -3916,7 +3920,7 @@ ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xC
+ 			}
+ 		}
+ 	}
+-	uno::Reference< sheet::XSpreadsheetView > xView( getCurrentExcelDoc()->getCurrentController(), uno::UNO_QUERY );
++	uno::Reference< sheet::XSpreadsheetView > xView( getCurrentExcelDoc(xContext)->getCurrentController(), uno::UNO_QUERY );
+ 	uno::Reference< table::XCellRange > xSheetRange( xView->getActiveSheet(), uno::UNO_QUERY_THROW ); 
+ 	ScVbaRange* pRange = new ScVbaRange( uno::Reference< XHelperInterface >(), xContext, xSheetRange );
+ 	uno::Reference< excel::XRange > xVbSheetRange( pRange );
+diff --git sc/source/ui/vba/vbaworkbook.cxx sc/source/ui/vba/vbaworkbook.cxx
+index 1c60441..5b6e277 100644
+--- sc/source/ui/vba/vbaworkbook.cxx
++++ sc/source/ui/vba/vbaworkbook.cxx
+@@ -64,7 +64,7 @@ class ActiveSheet : public ScVbaWorksheet
+ protected:
+ 	virtual uno::Reference< frame::XModel > getModel()
+ 	{ 	
+-		return getCurrentExcelDoc(); 
++		return getCurrentExcelDoc( mxContext ); 
+ 	}
+ 	virtual uno::Reference< sheet::XSpreadsheet > getSheet()
+ 	{ 
+@@ -218,7 +218,12 @@ ScVbaWorkbook::ScVbaWorkbook( uno::Sequence< uno::Any> const & args,
+ uno::Reference< excel::XWorksheet >
+ ScVbaWorkbook::getActiveSheet() throw (uno::RuntimeException)
+ {
+-	return new ActiveSheet( this, mxContext );
++	uno::Reference< frame::XModel > xModel( getCurrentExcelDoc( mxContext ) );	
++	uno::Reference< sheet::XSpreadsheet > xSheet;
++	uno::Reference< sheet::XSpreadsheetView > xView( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
++	if ( xView.is() )
++		xSheet = xView->getActiveSheet();
++	return new ScVbaWorksheet( this, mxContext, xSheet, xModel );
+ }
+ uno::Any SAL_CALL
+ ScVbaWorkbook::Sheets( const uno::Any& aIndex ) throw (uno::RuntimeException)
+diff --git sc/source/ui/vba/vbaworksheet.cxx sc/source/ui/vba/vbaworksheet.cxx
+index a416c8c..0323c4f 100644
+--- sc/source/ui/vba/vbaworksheet.cxx
++++ sc/source/ui/vba/vbaworksheet.cxx
+@@ -442,11 +442,11 @@ ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After ) throw (uno
+ 		uno::Reference<excel::XRange> xRange =  new ScVbaRange( this, mxContext, xRange1);
+ 		if (xRange.is())
+ 			xRange->Select();
+-		excel::implnCopy();
++		excel::implnCopy(mxModel);
+ 		uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
+ 		if (xModel.is()) 
+ 		{
+-			excel::implnPaste();
++			excel::implnPaste(xModel);
+ 			Delete();
+ 		}
+ 		return ;
+@@ -480,11 +480,11 @@ ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After ) throw (uno
+ 		uno::Reference<excel::XRange> xRange =  new ScVbaRange( this, mxContext, xRange1);
+ 		if (xRange.is())
+ 			xRange->Select();
+-		excel::implnCopy();
++		excel::implnCopy(mxModel);
+ 		uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
+ 		if (xModel.is())
+ 		{
+-			excel::implnPaste();
++			excel::implnPaste(xModel);
+ 		}
+ 		return;
+ 	}
+@@ -513,7 +513,7 @@ ScVbaWorksheet::Paste( const uno::Any& Destination, const uno::Any& /*Link*/ ) t
+ 	uno::Reference<excel::XRange> xRange( Destination, uno::UNO_QUERY );
+ 	if ( xRange.is() )
+ 		xRange->Select();
+-	excel::implnPaste();
++	excel::implnPaste( mxModel );
+ }
+ 
+ void 
+diff --git sc/source/ui/view/.tabview5.cxx.swp sc/source/ui/view/.tabview5.cxx.swp
+deleted file mode 100644
+index e3ca8cb..0000000
+Binary files sc/source/ui/view/.tabview5.cxx.swp and /dev/null differ
+diff --git sw/source/filter/ww8/ww8par.cxx sw/source/filter/ww8/ww8par.cxx
+index e1366a2..21a8014 100644
+--- sw/source/filter/ww8/ww8par.cxx
++++ sw/source/filter/ww8/ww8par.cxx
+@@ -4230,7 +4230,9 @@ ULONG SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos)
+ #endif 
+             // Create and insert Word vba Globals
+             uno::Any aGlobs;
+-            aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString::createFromAscii( "ooo.vba.word.Globals") );
++            uno::Sequence< uno::Any > aArgs(1);
++            aArgs[ 0 ] <<= mpDocShell->GetModel();
++            aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( ::rtl::OUString::createFromAscii( "ooo.vba.word.Globals"), aArgs );
+             mpDocShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", aGlobs );
+             
+             SvxImportMSVBasic aVBasic(*mpDocShell, *pStg,
+diff --git sw/source/ui/vba/vbaapplication.cxx sw/source/ui/vba/vbaapplication.cxx
+index 9c70772..ba57192 100644
+--- sw/source/ui/vba/vbaapplication.cxx
++++ sw/source/ui/vba/vbaapplication.cxx
+@@ -183,7 +183,7 @@ float SAL_CALL SwVbaApplication::CentimetersToPoints( float _Centimeters ) throw
+ uno::Reference< frame::XModel > 
+ SwVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException)
+ {
+-    return getCurrentWordDoc();
++    return getCurrentWordDoc( mxContext );
+ }
+ 
+ rtl::OUString& 
+diff --git sw/source/ui/vba/vbaglobals.cxx sw/source/ui/vba/vbaglobals.cxx
+index acf6b06..935a95c 100644
+--- sw/source/ui/vba/vbaglobals.cxx
++++ sw/source/ui/vba/vbaglobals.cxx
+@@ -42,15 +42,22 @@ using namespace ::com::sun::star::uno;
+ using namespace ::ooo::vba;
+ 
+ 
++rtl::OUString sDocCtxName( RTL_CONSTASCII_USTRINGPARAM("WordDocumentContext") );
+ 
+ // =============================================================================
+ // SwVbaGlobals
+ // =============================================================================
+ 
+-SwVbaGlobals::SwVbaGlobals(  css::uno::Reference< css::uno::XComponentContext >const& rxContext ) : SwVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext )
++SwVbaGlobals::SwVbaGlobals(  uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : SwVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, sDocCtxName )
+ {
+ 	OSL_TRACE("SwVbaGlobals::SwVbaGlobals()");
+-	init( rxContext, uno::makeAny( getApplication() ) );
++        uno::Sequence< beans::PropertyValue > aInitArgs( 2 );
++        aInitArgs[ 0 ].Name = rtl::OUString::createFromAscii("Application");
++        aInitArgs[ 0 ].Value = uno::makeAny( getApplication() );
++        aInitArgs[ 1 ].Name = sDocCtxName;
++        aInitArgs[ 1 ].Value = uno::makeAny( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ) );
++        
++        init( aInitArgs );
+ }
+ 
+ SwVbaGlobals::~SwVbaGlobals()
+@@ -65,8 +72,10 @@ uno::Reference<word::XApplication >
+ SwVbaGlobals::getApplication() throw (uno::RuntimeException)
+ {
+ 	OSL_TRACE("In SwVbaGlobals::getApplication");	
+-	static  uno::Reference< word::XApplication > WordApplication( new SwVbaApplication( mxContext) );
+-   	return WordApplication; 
++	if ( !mxApplication.is() )
++		 mxApplication.set( new SwVbaApplication( mxContext) );
++        
++   	return mxApplication; 
+ }
+ 
+ uno::Reference<word::XSystem > SAL_CALL
+@@ -178,7 +187,7 @@ SwVbaGlobals::getAvailableServiceNames(  ) throw (uno::RuntimeException)
+ namespace globals
+ {
+ namespace sdecl = comphelper::service_decl;
+-sdecl::vba_service_class_<SwVbaGlobals, sdecl::with_args<false> > serviceImpl;
++sdecl::vba_service_class_<SwVbaGlobals, sdecl::with_args<true> > serviceImpl;
+ extern sdecl::ServiceDecl const serviceDecl(
+     serviceImpl,
+     "SwVbaGlobals",
+diff --git sw/source/ui/vba/vbaglobals.hxx sw/source/ui/vba/vbaglobals.hxx
+index 267b1ed..066282e 100644
+--- sw/source/ui/vba/vbaglobals.hxx
++++ sw/source/ui/vba/vbaglobals.hxx
+@@ -58,7 +58,7 @@ private:
+ 
+ public:
+ 	
+-    SwVbaGlobals( css::uno::Reference< css::uno::XComponentContext >const& rxContext );
++    SwVbaGlobals( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& rxContext );
+     virtual ~SwVbaGlobals();
+ 
+     // XGlobals
+diff --git sw/source/ui/vba/vbasystem.cxx sw/source/ui/vba/vbasystem.cxx
+index c68a7c0..3a16e23 100644
+--- sw/source/ui/vba/vbasystem.cxx
++++ sw/source/ui/vba/vbasystem.cxx
+@@ -88,7 +88,7 @@ SwVbaSystem::~SwVbaSystem()
+ sal_Int32 SAL_CALL
+ SwVbaSystem::getCursor() throw (uno::RuntimeException)
+ {
+-    sal_Int32 nPointerStyle =  getPointerStyle( getCurrentWordDoc() );
++    sal_Int32 nPointerStyle =  getPointerStyle( getCurrentWordDoc(mxContext) );
+ 
+     switch( nPointerStyle )
+     {
+@@ -115,27 +115,27 @@ SwVbaSystem::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException)
+             case word::WdCursorType::wdCursorNorthwestArrow:
+             {
+                 const Pointer& rPointer( POINTER_ARROW );
+-                setCursorHelper( getCurrentWordDoc(), rPointer, sal_False );
++                setCursorHelper( getCurrentWordDoc(mxContext), rPointer, sal_False );
+                 break;
+             }
+             case word::WdCursorType::wdCursorWait:
+             {
+                 const Pointer& rPointer( static_cast< PointerStyle >( POINTER_WAIT ) );
+                 //It will set the edit window, toobar and statusbar's mouse pointer.
+-                setCursorHelper( getCurrentWordDoc(), rPointer, sal_True );
++                setCursorHelper( getCurrentWordDoc(mxContext), rPointer, sal_True );
+                 break;
+             }
+             case word::WdCursorType::wdCursorIBeam:
+             {
+                 const Pointer& rPointer( static_cast< PointerStyle >( POINTER_TEXT ) );
+                 //It will set the edit window, toobar and statusbar's mouse pointer.
+-                setCursorHelper( getCurrentWordDoc(), rPointer, sal_True );
++                setCursorHelper( getCurrentWordDoc( mxContext ), rPointer, sal_True );
+                 break;
+             }
+             case word::WdCursorType::wdCursorNormal:
+             {
+                 const Pointer& rPointer( POINTER_NULL );
+-                setCursorHelper( getCurrentWordDoc(), rPointer, sal_False );
++                setCursorHelper( getCurrentWordDoc( mxContext ), rPointer, sal_False );
+                 break;
+             }
+             default:
+diff --git vbahelper/inc/vbahelper/vbaglobalbase.hxx vbahelper/inc/vbahelper/vbaglobalbase.hxx
+index f9c0d25..d12040d 100644
+--- vbahelper/inc/vbahelper/vbaglobalbase.hxx
++++ vbahelper/inc/vbahelper/vbaglobalbase.hxx
+@@ -40,10 +40,10 @@ class VBAHELPER_DLLPUBLIC VbaGlobalsBase : public Globals_BASE
+ protected:
+ 
+     bool hasServiceName( const rtl::OUString& serviceName );
+-    void init(  const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Any& aApplication );
++    void init(  const css::uno::Sequence< css::beans::PropertyValue >& aInitArgs );
+ 
+ public:
+-    VbaGlobalsBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext);
++    VbaGlobalsBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const rtl::OUString& sDocCtxName );
+     virtual ~VbaGlobalsBase(){};
+     // XMultiServiceFactory
+     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (css::uno::Exception, css::uno::RuntimeException);
+diff --git vbahelper/inc/vbahelper/vbahelper.hxx vbahelper/inc/vbahelper/vbahelper.hxx
+index 3773474..5d97b81 100644
+--- vbahelper/inc/vbahelper/vbahelper.hxx
++++ vbahelper/inc/vbahelper/vbahelper.hxx
+@@ -67,8 +67,8 @@ namespace ooo
+         VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > createVBAUnoAPIService( SfxObjectShell* pShell,  const sal_Char* _pAsciiName ) throw (css::uno::RuntimeException);
+         VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs( SfxObjectShell* pShell,  const sal_Char* _pAsciiName, const css::uno::Sequence< css::uno::Any >& aArgs ) throw (css::uno::RuntimeException);
+         css::uno::Reference< css::frame::XModel > getCurrentDoc( const rtl::OUString& sKey ) throw (css::uno::RuntimeException);
+-        VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentExcelDoc() throw (css::uno::RuntimeException);
+-        VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc() throw (css::uno::RuntimeException);
++        VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException);
++        VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException);
+ 
+ 		VBAHELPER_DLLPUBLIC css::uno::Reference< css::beans::XIntrospectionAccess > getIntrospectionAccess( const css::uno::Any& aObject ) throw (css::uno::RuntimeException);
+ 		VBAHELPER_DLLPUBLIC css::uno::Reference< css::script::XTypeConverter > getTypeConverter( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException);
+diff --git vbahelper/source/vbahelper/vbaglobalbase.cxx vbahelper/source/vbahelper/vbaglobalbase.cxx
+index 3ce0f72..bc0eda2 100644
+--- vbahelper/source/vbahelper/vbaglobalbase.cxx
++++ vbahelper/source/vbahelper/vbaglobalbase.cxx
+@@ -41,28 +41,41 @@
+ using namespace com::sun::star;
+ using namespace ooo::vba;
+ 
++rtl::OUString sApplication( RTL_CONSTASCII_USTRINGPARAM("Application") );
++
+ VbaGlobalsBase::VbaGlobalsBase( 
+ const uno::Reference< ov::XHelperInterface >& xParent, 
+-const uno::Reference< uno::XComponentContext >& xContext) 
++const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sDocCtxName ) 
+ :  Globals_BASE( xParent, xContext )
+ {
+     // overwrite context with custom one ( that contains the application )
+     ::cppu::ContextEntry_Init aHandlerContextInfo[] =
+     {
+-        ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Application" ) ), uno::Any() ) 
++        ::cppu::ContextEntry_Init( sApplication, uno::Any() ), 
++        ::cppu::ContextEntry_Init( sDocCtxName, uno::Any() ), 
+     };
+ 
+     mxContext = ::cppu::createComponentContext( aHandlerContextInfo, sizeof( aHandlerContextInfo ) / sizeof( aHandlerContextInfo[0] ), xContext );
+ 
+ }
+ 
++
+ void
+-VbaGlobalsBase::init(  uno::Reference< uno::XComponentContext >const& rxContext, const uno::Any& aApplication )
++VbaGlobalsBase::init(  const uno::Sequence< beans::PropertyValue >& aInitArgs )
+ {
+-            uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY_THROW );
+-            xNameContainer->replaceByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Application") ), aApplication );
+-            uno::Reference< XHelperInterface > xParent( aApplication, uno::UNO_QUERY );
++    sal_Int32 nLen = aInitArgs.getLength();
++    for ( sal_Int32 nIndex = 0; nIndex < nLen; ++nIndex )
++    {
++        uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY_THROW );
++        if ( aInitArgs[ nIndex ].Name.equals( sApplication ) )
++        {
++            xNameContainer->replaceByName( sApplication, aInitArgs[ nIndex ].Value );
++            uno::Reference< XHelperInterface > xParent( aInitArgs[ nIndex ].Value, uno::UNO_QUERY );
+             mxParent = xParent;
++        }
++        else 
++            xNameContainer->replaceByName( aInitArgs[ nIndex ].Name, aInitArgs[ nIndex ].Value );
++    }
+ }
+ 
+ uno::Reference< uno::XInterface > SAL_CALL 
+diff --git vbahelper/source/vbahelper/vbahelper.cxx vbahelper/source/vbahelper/vbahelper.cxx
+index 8290f66..110d15f 100644
+--- vbahelper/source/vbahelper/vbahelper.cxx
++++ vbahelper/source/vbahelper/vbahelper.cxx
+@@ -458,19 +458,46 @@ getCurrentDoc( const rtl::OUString& sKey ) throw (uno::RuntimeException)
+ 	return xModel;
+ }
+ 
++ uno::Reference< frame::XModel > 
++getCurrentDocCtx( const rtl::OUString& ctxName, const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
++{
++    uno::Reference< frame::XModel > xModel;
++     // try fallback to calling doc
++     css::uno::Reference< css::container::XNameAccess > xNameAccess( xContext, css::uno::UNO_QUERY_THROW );
++     xModel.set( xNameAccess->getByName( ctxName ), uno::UNO_QUERY_THROW );
++     return xModel;
++}
+ 
+  uno::Reference< frame::XModel > 
+-getCurrentExcelDoc() throw (uno::RuntimeException)
++getCurrentExcelDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
+ {
+-   static const rtl::OUString sThisExcelDoc( RTL_CONSTASCII_USTRINGPARAM("ThisExcelDoc" ) );
+-   return getCurrentDoc( sThisExcelDoc ); 
++    static const rtl::OUString sThisExcelDoc( RTL_CONSTASCII_USTRINGPARAM("ThisExcelDoc" ) );
++    uno::Reference< frame::XModel > xModel;
++    try
++    {
++        xModel = getCurrentDoc( sThisExcelDoc ); 
++    }
++    catch( uno::Exception& e )
++    {
++        xModel = getCurrentDocCtx( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ExcelDocumentContext" ) ), xContext );
++    }
++    return xModel;
+ }
+ 
+  uno::Reference< frame::XModel > 
+-getCurrentWordDoc() throw (uno::RuntimeException)
++getCurrentWordDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
+ {
+-   static const rtl::OUString sThisWordDoc( RTL_CONSTASCII_USTRINGPARAM("ThisWordDoc" ) );
+-   return getCurrentDoc( sThisWordDoc ); 
++    static const rtl::OUString sThisWordDoc( RTL_CONSTASCII_USTRINGPARAM("ThisWordDoc" ) );
++    uno::Reference< frame::XModel > xModel;
++    try
++    {
++        xModel = getCurrentDoc( sThisWordDoc ); 
++    }
++    catch( uno::Exception& e )
++    {
++        xModel = getCurrentDocCtx( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WordDocumentContext" ) ), xContext );
++    }
++    return xModel;
+ }
+ 
+ sal_Int32 


More information about the ooo-build-commit mailing list