update ooo310-m15
[ooovba.git] / applied_patches / 0455-vba-fallback-to-calling-doc-context.diff
blob2f761cfde0b6edcafb8f51b577f70a152b1ce3cb
1 diff --git sc/source/filter/excel/excimp8.cxx sc/source/filter/excel/excimp8.cxx
2 index 4d1db8b..e064e41 100644
3 --- sc/source/filter/excel/excimp8.cxx
4 +++ sc/source/filter/excel/excimp8.cxx
5 @@ -276,7 +276,9 @@ void ImportExcel8::ReadBasic( void )
6 if( bLoadCode || bLoadStrg )
8 uno::Any aGlobs;
9 - aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString::createFromAscii( "ooo.vba.excel.Globals") );
10 + uno::Sequence< uno::Any > aArgs(1);
11 + aArgs[ 0 ] <<= pShell->GetModel();
12 + aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( ::rtl::OUString::createFromAscii( "ooo.vba.excel.Globals"), aArgs );
13 pShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", aGlobs );
14 SvxImportMSVBasic aBasicImport( *pShell, *xRootStrg, bLoadCode, bLoadStrg );
15 bool bAsComment = !bLoadExecutable || !aGlobs.hasValue();
16 diff --git sc/source/ui/vba/excelvbahelper.cxx sc/source/ui/vba/excelvbahelper.cxx
17 index 5f133d9..d4f8967 100644
18 --- sc/source/ui/vba/excelvbahelper.cxx
19 +++ sc/source/ui/vba/excelvbahelper.cxx
20 @@ -107,10 +107,10 @@ public:
23 void
24 -implnPaste()
25 +implnPaste( const uno::Reference< frame::XModel>& xModel )
27 PasteCellsWarningReseter resetWarningBox;
28 - ScTabViewShell* pViewShell = getCurrentBestViewShell();
29 + ScTabViewShell* pViewShell = getBestViewShell( xModel );
30 if ( pViewShell )
32 pViewShell->PasteFromSystem();
33 @@ -120,31 +120,28 @@ implnPaste()
36 void
37 -implnCopy()
38 +implnCopy( const uno::Reference< frame::XModel>& xModel )
40 - ScTabViewShell* pViewShell = getCurrentBestViewShell();
41 + ScTabViewShell* pViewShell = getBestViewShell( xModel );
42 if ( pViewShell )
43 pViewShell->CopyToClip(NULL,false,false,true);
46 void
47 -implnCut()
48 +implnCut( const uno::Reference< frame::XModel>& xModel )
50 - ScTabViewShell* pViewShell = getCurrentBestViewShell();
51 + ScTabViewShell* pViewShell = getBestViewShell( xModel );
52 if ( pViewShell )
53 pViewShell->CutToClip( NULL, TRUE );
56 -void implnPasteSpecial(USHORT nFlags,USHORT nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose)
57 +void implnPasteSpecial( const uno::Reference< frame::XModel>& xModel, USHORT nFlags,USHORT nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose)
59 PasteCellsWarningReseter resetWarningBox;
60 sal_Bool bAsLink(sal_False), bOtherDoc(sal_False);
61 InsCellCmd eMoveMode = INS_NONE;
63 - ScTabViewShell* pTabViewShell = ScTabViewShell::GetActiveViewShell();
64 - if ( !pTabViewShell )
65 - // none active, try next best
66 - pTabViewShell = getCurrentBestViewShell();
67 + ScTabViewShell* pTabViewShell = getBestViewShell( xModel );
68 if ( pTabViewShell )
70 ScViewData* pView = pTabViewShell->GetViewData();
71 @@ -191,16 +188,16 @@ getBestViewShell( const css::uno::Reference< css::frame::XModel>& xModel )
74 ScTabViewShell*
75 -getCurrentBestViewShell()
76 +getCurrentBestViewShell( const uno::Reference< uno::XComponentContext >& xContext )
78 - uno::Reference< frame::XModel > xModel = getCurrentExcelDoc();
79 + uno::Reference< frame::XModel > xModel = getCurrentExcelDoc( xContext );
80 return getBestViewShell( xModel );
83 SfxViewFrame*
84 -getCurrentViewFrame()
85 +getViewFrame( const uno::Reference< frame::XModel >& xModel )
87 - ScTabViewShell* pViewShell = getCurrentBestViewShell();
88 + ScTabViewShell* pViewShell = getBestViewShell( xModel );
89 if ( pViewShell )
90 return pViewShell->GetViewFrame();
91 return NULL;
92 diff --git sc/source/ui/vba/excelvbahelper.hxx sc/source/ui/vba/excelvbahelper.hxx
93 index 3a3b7f8..8c7c430 100644
94 --- sc/source/ui/vba/excelvbahelper.hxx
95 +++ sc/source/ui/vba/excelvbahelper.hxx
96 @@ -41,15 +41,15 @@ namespace ooo
97 namespace excel
99 // nTabs empty means apply zoom to all sheets
100 void implSetZoom( const css::uno::Reference< css::frame::XModel >& xModel, sal_Int16 nZoom, std::vector< SCTAB >& nTabs );
101 - void implnCopy();
102 - void implnPaste();
103 - void implnCut();
104 - void implnPasteSpecial(sal_uInt16 nFlags,sal_uInt16 nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose);
105 + void implnCopy( const css::uno::Reference< css::frame::XModel>& xModel );
106 + void implnPaste ( const css::uno::Reference< css::frame::XModel>& xModel );
107 + void implnCut( const css::uno::Reference< css::frame::XModel>& xModel );
108 + void implnPasteSpecial( const css::uno::Reference< css::frame::XModel>& xModel, sal_uInt16 nFlags,sal_uInt16 nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose);
109 ScTabViewShell* getBestViewShell( const css::uno::Reference< css::frame::XModel>& xModel ) ;
110 ScDocShell* getDocShell( const css::uno::Reference< css::frame::XModel>& xModel ) ;
111 - ScTabViewShell* getCurrentBestViewShell();
112 - SfxViewFrame* getCurrentViewFrame();
113 + ScTabViewShell* getCurrentBestViewShell( const css::uno::Reference< css::uno::XComponentContext >& xContext );
114 + SfxViewFrame* getViewFrame( const css::uno::Reference< css::frame::XModel >& xModel );
115 class ScVbaCellRangeAccess
117 public:
118 diff --git sc/source/ui/vba/vbaapplication.cxx sc/source/ui/vba/vbaapplication.cxx
119 index 68d0834..68dff2f 100644
120 --- sc/source/ui/vba/vbaapplication.cxx
121 +++ sc/source/ui/vba/vbaapplication.cxx
122 @@ -125,7 +125,7 @@ class ActiveWorkbook : public ScVbaWorkbook
123 protected:
124 virtual uno::Reference< frame::XModel > getModel()
126 - return getCurrentExcelDoc();
127 + return getCurrentExcelDoc(mxContext);
129 public:
130 ActiveWorkbook( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext) : ScVbaWorkbook( xParent, xContext ){}
131 @@ -230,7 +230,7 @@ ScVbaApplication::getActiveCell() throw (uno::RuntimeException )
133 uno::Reference< sheet::XSpreadsheetView > xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW );
134 uno::Reference< table::XCellRange > xRange( xView->getActiveSheet(), ::uno::UNO_QUERY_THROW);
135 - ScTabViewShell* pViewShell = excel::getCurrentBestViewShell();
136 + ScTabViewShell* pViewShell = excel::getCurrentBestViewShell(mxContext);
137 if ( !pViewShell )
138 throw uno::RuntimeException( rtl::OUString::createFromAscii("No ViewShell available"), uno::Reference< uno::XInterface >() );
139 ScViewData* pTabView = pViewShell->GetViewData();
140 @@ -509,7 +509,7 @@ ScVbaApplication::GoTo( const uno::Any& Reference, const uno::Any& Scroll ) thro
141 xModel->getCurrentController(), uno::UNO_QUERY_THROW );
142 uno::Reference< sheet::XSpreadsheet > xDoc = xSpreadsheet->getActiveSheet();
144 - ScTabViewShell* pShell = excel::getCurrentBestViewShell();
145 + ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
146 ScGridWindow* gridWindow = (ScGridWindow*)pShell->GetWindow();
149 @@ -551,7 +551,7 @@ ScVbaApplication::GoTo( const uno::Any& Reference, const uno::Any& Scroll ) thro
150 if( Reference >>= xRange )
152 uno::Reference< excel::XRange > xVbaRange( Reference, uno::UNO_QUERY );
153 - ScTabViewShell* pShell = excel::getCurrentBestViewShell();
154 + ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext );
155 ScGridWindow* gridWindow = (ScGridWindow*)pShell->GetWindow();
156 if ( xVbaRange.is() )
158 @@ -1135,7 +1135,7 @@ ScVbaApplication::Volatile( const uno::Any& aVolatile ) throw ( uno::RuntimeExc
159 ScVbaApplication::getDisplayFormulaBar() throw ( css::uno::RuntimeException )
161 sal_Bool bRes = sal_False;
162 - ScTabViewShell* pViewShell = excel::getCurrentBestViewShell();
163 + ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext );
164 if ( pViewShell )
166 SfxBoolItem sfxFormBar( FID_TOGGLEINPUTLINE);
167 @@ -1153,7 +1153,7 @@ ScVbaApplication::getDisplayFormulaBar() throw ( css::uno::RuntimeException )
168 void SAL_CALL
169 ScVbaApplication::setDisplayFormulaBar( ::sal_Bool _displayformulabar ) throw ( css::uno::RuntimeException )
171 - ScTabViewShell* pViewShell = excel::getCurrentBestViewShell();
172 + ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext );
173 if ( pViewShell && ( _displayformulabar != getDisplayFormulaBar() ) )
175 SfxBoolItem sfxFormBar( FID_TOGGLEINPUTLINE, _displayformulabar);
176 @@ -1185,7 +1185,7 @@ ScVbaApplication::Caller( const uno::Any& /*aIndex*/ ) throw ( uno::RuntimeExcep
177 uno::Reference< frame::XModel >
178 ScVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException)
180 - return getCurrentExcelDoc();
181 + return getCurrentExcelDoc(mxContext);
184 uno::Any SAL_CALL
185 diff --git sc/source/ui/vba/vbachartobject.cxx sc/source/ui/vba/vbachartobject.cxx
186 index 71942f1..2a2899e 100644
187 --- sc/source/ui/vba/vbachartobject.cxx
188 +++ sc/source/ui/vba/vbachartobject.cxx
189 @@ -124,7 +124,7 @@ ScVbaChartObject::Activate() throw ( script::BasicErrorException )
190 // fact probably the chart object should be created with
191 // the XModel owner
192 //uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getXModel().getCurrentController());
193 - uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getCurrentExcelDoc()->getCurrentController(), uno::UNO_QUERY_THROW );
194 + uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getCurrentExcelDoc(mxContext)->getCurrentController(), uno::UNO_QUERY_THROW );
195 xSelectionSupplier->select(uno::makeAny(xShape));
197 catch (uno::Exception& )
198 diff --git sc/source/ui/vba/vbaglobals.cxx sc/source/ui/vba/vbaglobals.cxx
199 index ac5e4f5..6181cf0 100644
200 --- sc/source/ui/vba/vbaglobals.cxx
201 +++ sc/source/ui/vba/vbaglobals.cxx
202 @@ -50,10 +50,20 @@ using namespace ::ooo::vba;
203 // ScVbaGlobals
204 // =============================================================================
206 -ScVbaGlobals::ScVbaGlobals( css::uno::Reference< css::uno::XComponentContext >const& rxContext ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext )
207 +//ScVbaGlobals::ScVbaGlobals( css::uno::Reference< css::uno::XComponentContext >const& rxContext, ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext )
208 +rtl::OUString sDocCtxName( RTL_CONSTASCII_USTRINGPARAM("ExcelDocumentContext") );
210 +ScVbaGlobals::ScVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, sDocCtxName )
212 OSL_TRACE("ScVbaGlobals::ScVbaGlobals()");
213 - init( rxContext, uno::Any( getApplication() ) );
215 + uno::Sequence< beans::PropertyValue > aInitArgs( 2 );
216 + aInitArgs[ 0 ].Name = rtl::OUString::createFromAscii("Application");
217 + aInitArgs[ 0 ].Value = uno::makeAny( getApplication() );
218 + aInitArgs[ 1 ].Name = sDocCtxName;
219 + aInitArgs[ 1 ].Value = uno::makeAny( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ) );
221 + init( aInitArgs );
224 ScVbaGlobals::~ScVbaGlobals()
225 @@ -68,8 +78,9 @@ uno::Reference<excel::XApplication >
226 ScVbaGlobals::getApplication() throw (uno::RuntimeException)
228 // OSL_TRACE("In ScVbaGlobals::getApplication");
229 - static uno::Reference< excel::XApplication > ExcelApplication( new ScVbaApplication( mxContext) );
230 - return ExcelApplication;
231 + if ( !mxApplication.is() )
232 + mxApplication.set( new ScVbaApplication( mxContext) );
233 + return mxApplication;
236 uno::Reference< excel::XWorkbook > SAL_CALL
237 @@ -264,7 +275,7 @@ ScVbaGlobals::getServiceNames()
238 namespace globals
240 namespace sdecl = comphelper::service_decl;
241 -sdecl::vba_service_class_<ScVbaGlobals, sdecl::with_args<false> > serviceImpl;
242 +sdecl::vba_service_class_<ScVbaGlobals, sdecl::with_args<true> > serviceImpl;
243 extern sdecl::ServiceDecl const serviceDecl(
244 serviceImpl,
245 "ScVbaGlobals",
246 diff --git sc/source/ui/vba/vbaglobals.hxx sc/source/ui/vba/vbaglobals.hxx
247 index 66dd1fa..53838b9 100644
248 --- sc/source/ui/vba/vbaglobals.hxx
249 +++ sc/source/ui/vba/vbaglobals.hxx
250 @@ -48,13 +48,16 @@ typedef ::cppu::ImplInheritanceHelper1< VbaGlobalsBase, ov::excel::XGlobals > Sc
252 class ScVbaGlobals : public ScVbaGlobals_BASE
254 + css::uno::Reference< ov::excel::XApplication > mxApplication;
255 virtual css::uno::Reference<
256 ov::excel::XApplication > SAL_CALL getApplication()
257 throw (css::uno::RuntimeException);
258 public:
260 - ScVbaGlobals(
261 + ScVbaGlobals( css::uno::Sequence< css::uno::Any > const& aArgs,
262 css::uno::Reference< css::uno::XComponentContext >const& rxContext );
263 + //ScVbaGlobals(
264 + // css::uno::Reference< css::uno::XComponentContext >const& rxContext, );
265 virtual ~ScVbaGlobals();
267 // XGlobals
268 diff --git sc/source/ui/vba/vbarange.cxx sc/source/ui/vba/vbarange.cxx
269 index 4512c46..a3907a7 100644
270 --- sc/source/ui/vba/vbarange.cxx
271 +++ sc/source/ui/vba/vbarange.cxx
272 @@ -1996,9 +1996,9 @@ bool cellInRange( const table::CellRangeAddress& rAddr, const sal_Int32& nCol, c
273 return false;
276 -void setCursor( const SCCOL& nCol, const SCROW& nRow, bool bInSel = true )
277 +void setCursor( const SCCOL& nCol, const SCROW& nRow, const uno::Reference< frame::XModel >& xModel, bool bInSel = true )
279 - ScTabViewShell* pShell = excel::getCurrentBestViewShell();
280 + ScTabViewShell* pShell = excel::getBestViewShell( xModel );
281 if ( pShell )
283 if ( bInSel )
284 @@ -2045,7 +2045,7 @@ ScVbaRange::Activate() throw (uno::RuntimeException)
286 if ( cellInRange( nAddrs[index], thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
288 - setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ) );
289 + setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
290 return;
293 @@ -2053,7 +2053,7 @@ ScVbaRange::Activate() throw (uno::RuntimeException)
296 if ( xRange.is() && cellInRange( xRange->getRangeAddress(), thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
297 - setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ) );
298 + setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
299 else
301 // if this range is multi cell select the range other
302 @@ -2061,7 +2061,7 @@ ScVbaRange::Activate() throw (uno::RuntimeException)
303 if ( isSingleCellRange() )
304 // This top-leftmost cell of this Range is not in the current
305 // selection so just select this range
306 - setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), false );
307 + setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel, false );
308 else
309 Select();
311 @@ -2216,8 +2216,9 @@ ScVbaRange::Copy(const ::uno::Any& Destination) throw (uno::RuntimeException)
313 else
315 + uno::Reference< frame::XModel > xModel = getModelFromRange( mxRange );
316 Select();
317 - excel::implnCopy();
318 + excel::implnCopy( xModel );
322 @@ -2240,8 +2241,9 @@ ScVbaRange::Cut(const ::uno::Any& Destination) throw (uno::RuntimeException)
323 xMover->moveRange( xDestination->getCellAddress(), xSource->getRangeAddress() );
326 + uno::Reference< frame::XModel > xModel = getModelFromRange( mxRange );
327 Select();
328 - excel::implnCut();
329 + excel::implnCut( xModel );
333 @@ -2574,7 +2576,7 @@ ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, cons
335 USHORT nFlags = getPasteFlags(nPaste);
336 USHORT nFormulaBits = getPasteFormulaBits(nOperation);
337 - excel::implnPasteSpecial(nFlags,nFormulaBits,bSkipBlanks,bTranspose);
338 + excel::implnPasteSpecial(pShell->GetModel(), nFlags,nFormulaBits,bSkipBlanks,bTranspose);
339 // restore selection
340 xSelection->select( uno::makeAny( xSel ) );
342 @@ -3249,7 +3251,9 @@ ScVbaRange::End( ::sal_Int32 Direction ) throw (uno::RuntimeException)
343 // position current cell upper left of this range
344 Cells( uno::makeAny( (sal_Int32) 1 ), uno::makeAny( (sal_Int32) 1 ) )->Select();
346 - SfxViewFrame* pViewFrame = excel::getCurrentViewFrame();
347 + uno::Reference< frame::XModel > xModel = getModelFromRange( mxRange );
349 + SfxViewFrame* pViewFrame = excel::getViewFrame( xModel );
350 if ( pViewFrame )
352 SfxAllItemSet aArgs( SFX_APP()->GetPool() );
353 @@ -3893,7 +3897,7 @@ ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xC
354 if ( Cell1.hasValue() && !Cell2.hasValue() && sRangeName.getLength() )
356 const static rtl::OUString sNamedRanges( RTL_CONSTASCII_USTRINGPARAM("NamedRanges"));
357 - uno::Reference< beans::XPropertySet > xPropSet( getCurrentExcelDoc(), uno::UNO_QUERY_THROW );
358 + uno::Reference< beans::XPropertySet > xPropSet( getCurrentExcelDoc(xContext), uno::UNO_QUERY_THROW );
360 uno::Reference< container::XNameAccess > xNamed( xPropSet->getPropertyValue( sNamedRanges ), uno::UNO_QUERY_THROW );
361 uno::Reference< sheet::XCellRangeReferrer > xReferrer;
362 @@ -3916,7 +3920,7 @@ ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xC
366 - uno::Reference< sheet::XSpreadsheetView > xView( getCurrentExcelDoc()->getCurrentController(), uno::UNO_QUERY );
367 + uno::Reference< sheet::XSpreadsheetView > xView( getCurrentExcelDoc(xContext)->getCurrentController(), uno::UNO_QUERY );
368 uno::Reference< table::XCellRange > xSheetRange( xView->getActiveSheet(), uno::UNO_QUERY_THROW );
369 ScVbaRange* pRange = new ScVbaRange( uno::Reference< XHelperInterface >(), xContext, xSheetRange );
370 uno::Reference< excel::XRange > xVbSheetRange( pRange );
371 diff --git sc/source/ui/vba/vbaworkbook.cxx sc/source/ui/vba/vbaworkbook.cxx
372 index 1c60441..5b6e277 100644
373 --- sc/source/ui/vba/vbaworkbook.cxx
374 +++ sc/source/ui/vba/vbaworkbook.cxx
375 @@ -64,7 +64,7 @@ class ActiveSheet : public ScVbaWorksheet
376 protected:
377 virtual uno::Reference< frame::XModel > getModel()
379 - return getCurrentExcelDoc();
380 + return getCurrentExcelDoc( mxContext );
382 virtual uno::Reference< sheet::XSpreadsheet > getSheet()
384 @@ -218,7 +218,12 @@ ScVbaWorkbook::ScVbaWorkbook( uno::Sequence< uno::Any> const & args,
385 uno::Reference< excel::XWorksheet >
386 ScVbaWorkbook::getActiveSheet() throw (uno::RuntimeException)
388 - return new ActiveSheet( this, mxContext );
389 + uno::Reference< frame::XModel > xModel( getCurrentExcelDoc( mxContext ) );
390 + uno::Reference< sheet::XSpreadsheet > xSheet;
391 + uno::Reference< sheet::XSpreadsheetView > xView( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
392 + if ( xView.is() )
393 + xSheet = xView->getActiveSheet();
394 + return new ScVbaWorksheet( this, mxContext, xSheet, xModel );
396 uno::Any SAL_CALL
397 ScVbaWorkbook::Sheets( const uno::Any& aIndex ) throw (uno::RuntimeException)
398 diff --git sc/source/ui/vba/vbaworksheet.cxx sc/source/ui/vba/vbaworksheet.cxx
399 index a416c8c..0323c4f 100644
400 --- sc/source/ui/vba/vbaworksheet.cxx
401 +++ sc/source/ui/vba/vbaworksheet.cxx
402 @@ -442,11 +442,11 @@ ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After ) throw (uno
403 uno::Reference<excel::XRange> xRange = new ScVbaRange( this, mxContext, xRange1);
404 if (xRange.is())
405 xRange->Select();
406 - excel::implnCopy();
407 + excel::implnCopy(mxModel);
408 uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
409 if (xModel.is())
411 - excel::implnPaste();
412 + excel::implnPaste(xModel);
413 Delete();
415 return ;
416 @@ -480,11 +480,11 @@ ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After ) throw (uno
417 uno::Reference<excel::XRange> xRange = new ScVbaRange( this, mxContext, xRange1);
418 if (xRange.is())
419 xRange->Select();
420 - excel::implnCopy();
421 + excel::implnCopy(mxModel);
422 uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
423 if (xModel.is())
425 - excel::implnPaste();
426 + excel::implnPaste(xModel);
428 return;
430 @@ -513,7 +513,7 @@ ScVbaWorksheet::Paste( const uno::Any& Destination, const uno::Any& /*Link*/ ) t
431 uno::Reference<excel::XRange> xRange( Destination, uno::UNO_QUERY );
432 if ( xRange.is() )
433 xRange->Select();
434 - excel::implnPaste();
435 + excel::implnPaste( mxModel );
438 void
439 diff --git sc/source/ui/view/.tabview5.cxx.swp sc/source/ui/view/.tabview5.cxx.swp
440 deleted file mode 100644
441 index e3ca8cb..0000000
442 Binary files sc/source/ui/view/.tabview5.cxx.swp and /dev/null differ
443 diff --git sw/source/filter/ww8/ww8par.cxx sw/source/filter/ww8/ww8par.cxx
444 index e1366a2..21a8014 100644
445 --- sw/source/filter/ww8/ww8par.cxx
446 +++ sw/source/filter/ww8/ww8par.cxx
447 @@ -4230,7 +4230,9 @@ ULONG SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos)
448 #endif
449 // Create and insert Word vba Globals
450 uno::Any aGlobs;
451 - aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString::createFromAscii( "ooo.vba.word.Globals") );
452 + uno::Sequence< uno::Any > aArgs(1);
453 + aArgs[ 0 ] <<= mpDocShell->GetModel();
454 + aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( ::rtl::OUString::createFromAscii( "ooo.vba.word.Globals"), aArgs );
455 mpDocShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", aGlobs );
457 SvxImportMSVBasic aVBasic(*mpDocShell, *pStg,
458 diff --git sw/source/ui/vba/vbaapplication.cxx sw/source/ui/vba/vbaapplication.cxx
459 index 9c70772..ba57192 100644
460 --- sw/source/ui/vba/vbaapplication.cxx
461 +++ sw/source/ui/vba/vbaapplication.cxx
462 @@ -183,7 +183,7 @@ float SAL_CALL SwVbaApplication::CentimetersToPoints( float _Centimeters ) throw
463 uno::Reference< frame::XModel >
464 SwVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException)
466 - return getCurrentWordDoc();
467 + return getCurrentWordDoc( mxContext );
470 rtl::OUString&
471 diff --git sw/source/ui/vba/vbaglobals.cxx sw/source/ui/vba/vbaglobals.cxx
472 index acf6b06..935a95c 100644
473 --- sw/source/ui/vba/vbaglobals.cxx
474 +++ sw/source/ui/vba/vbaglobals.cxx
475 @@ -42,15 +42,22 @@ using namespace ::com::sun::star::uno;
476 using namespace ::ooo::vba;
479 +rtl::OUString sDocCtxName( RTL_CONSTASCII_USTRINGPARAM("WordDocumentContext") );
481 // =============================================================================
482 // SwVbaGlobals
483 // =============================================================================
485 -SwVbaGlobals::SwVbaGlobals( css::uno::Reference< css::uno::XComponentContext >const& rxContext ) : SwVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext )
486 +SwVbaGlobals::SwVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : SwVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, sDocCtxName )
488 OSL_TRACE("SwVbaGlobals::SwVbaGlobals()");
489 - init( rxContext, uno::makeAny( getApplication() ) );
490 + uno::Sequence< beans::PropertyValue > aInitArgs( 2 );
491 + aInitArgs[ 0 ].Name = rtl::OUString::createFromAscii("Application");
492 + aInitArgs[ 0 ].Value = uno::makeAny( getApplication() );
493 + aInitArgs[ 1 ].Name = sDocCtxName;
494 + aInitArgs[ 1 ].Value = uno::makeAny( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ) );
496 + init( aInitArgs );
499 SwVbaGlobals::~SwVbaGlobals()
500 @@ -65,8 +72,10 @@ uno::Reference<word::XApplication >
501 SwVbaGlobals::getApplication() throw (uno::RuntimeException)
503 OSL_TRACE("In SwVbaGlobals::getApplication");
504 - static uno::Reference< word::XApplication > WordApplication( new SwVbaApplication( mxContext) );
505 - return WordApplication;
506 + if ( !mxApplication.is() )
507 + mxApplication.set( new SwVbaApplication( mxContext) );
509 + return mxApplication;
512 uno::Reference<word::XSystem > SAL_CALL
513 @@ -178,7 +187,7 @@ SwVbaGlobals::getAvailableServiceNames( ) throw (uno::RuntimeException)
514 namespace globals
516 namespace sdecl = comphelper::service_decl;
517 -sdecl::vba_service_class_<SwVbaGlobals, sdecl::with_args<false> > serviceImpl;
518 +sdecl::vba_service_class_<SwVbaGlobals, sdecl::with_args<true> > serviceImpl;
519 extern sdecl::ServiceDecl const serviceDecl(
520 serviceImpl,
521 "SwVbaGlobals",
522 diff --git sw/source/ui/vba/vbaglobals.hxx sw/source/ui/vba/vbaglobals.hxx
523 index 267b1ed..066282e 100644
524 --- sw/source/ui/vba/vbaglobals.hxx
525 +++ sw/source/ui/vba/vbaglobals.hxx
526 @@ -58,7 +58,7 @@ private:
528 public:
530 - SwVbaGlobals( css::uno::Reference< css::uno::XComponentContext >const& rxContext );
531 + SwVbaGlobals( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& rxContext );
532 virtual ~SwVbaGlobals();
534 // XGlobals
535 diff --git sw/source/ui/vba/vbasystem.cxx sw/source/ui/vba/vbasystem.cxx
536 index c68a7c0..3a16e23 100644
537 --- sw/source/ui/vba/vbasystem.cxx
538 +++ sw/source/ui/vba/vbasystem.cxx
539 @@ -88,7 +88,7 @@ SwVbaSystem::~SwVbaSystem()
540 sal_Int32 SAL_CALL
541 SwVbaSystem::getCursor() throw (uno::RuntimeException)
543 - sal_Int32 nPointerStyle = getPointerStyle( getCurrentWordDoc() );
544 + sal_Int32 nPointerStyle = getPointerStyle( getCurrentWordDoc(mxContext) );
546 switch( nPointerStyle )
548 @@ -115,27 +115,27 @@ SwVbaSystem::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException)
549 case word::WdCursorType::wdCursorNorthwestArrow:
551 const Pointer& rPointer( POINTER_ARROW );
552 - setCursorHelper( getCurrentWordDoc(), rPointer, sal_False );
553 + setCursorHelper( getCurrentWordDoc(mxContext), rPointer, sal_False );
554 break;
556 case word::WdCursorType::wdCursorWait:
558 const Pointer& rPointer( static_cast< PointerStyle >( POINTER_WAIT ) );
559 //It will set the edit window, toobar and statusbar's mouse pointer.
560 - setCursorHelper( getCurrentWordDoc(), rPointer, sal_True );
561 + setCursorHelper( getCurrentWordDoc(mxContext), rPointer, sal_True );
562 break;
564 case word::WdCursorType::wdCursorIBeam:
566 const Pointer& rPointer( static_cast< PointerStyle >( POINTER_TEXT ) );
567 //It will set the edit window, toobar and statusbar's mouse pointer.
568 - setCursorHelper( getCurrentWordDoc(), rPointer, sal_True );
569 + setCursorHelper( getCurrentWordDoc( mxContext ), rPointer, sal_True );
570 break;
572 case word::WdCursorType::wdCursorNormal:
574 const Pointer& rPointer( POINTER_NULL );
575 - setCursorHelper( getCurrentWordDoc(), rPointer, sal_False );
576 + setCursorHelper( getCurrentWordDoc( mxContext ), rPointer, sal_False );
577 break;
579 default:
580 diff --git vbahelper/inc/vbahelper/vbaglobalbase.hxx vbahelper/inc/vbahelper/vbaglobalbase.hxx
581 index f9c0d25..d12040d 100644
582 --- vbahelper/inc/vbahelper/vbaglobalbase.hxx
583 +++ vbahelper/inc/vbahelper/vbaglobalbase.hxx
584 @@ -40,10 +40,10 @@ class VBAHELPER_DLLPUBLIC VbaGlobalsBase : public Globals_BASE
585 protected:
587 bool hasServiceName( const rtl::OUString& serviceName );
588 - void init( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Any& aApplication );
589 + void init( const css::uno::Sequence< css::beans::PropertyValue >& aInitArgs );
591 public:
592 - VbaGlobalsBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext);
593 + VbaGlobalsBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const rtl::OUString& sDocCtxName );
594 virtual ~VbaGlobalsBase(){};
595 // XMultiServiceFactory
596 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (css::uno::Exception, css::uno::RuntimeException);
597 diff --git vbahelper/inc/vbahelper/vbahelper.hxx vbahelper/inc/vbahelper/vbahelper.hxx
598 index 3773474..5d97b81 100644
599 --- vbahelper/inc/vbahelper/vbahelper.hxx
600 +++ vbahelper/inc/vbahelper/vbahelper.hxx
601 @@ -67,8 +67,8 @@ namespace ooo
602 VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > createVBAUnoAPIService( SfxObjectShell* pShell, const sal_Char* _pAsciiName ) throw (css::uno::RuntimeException);
603 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);
604 css::uno::Reference< css::frame::XModel > getCurrentDoc( const rtl::OUString& sKey ) throw (css::uno::RuntimeException);
605 - VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentExcelDoc() throw (css::uno::RuntimeException);
606 - VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc() throw (css::uno::RuntimeException);
607 + VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException);
608 + VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException);
610 VBAHELPER_DLLPUBLIC css::uno::Reference< css::beans::XIntrospectionAccess > getIntrospectionAccess( const css::uno::Any& aObject ) throw (css::uno::RuntimeException);
611 VBAHELPER_DLLPUBLIC css::uno::Reference< css::script::XTypeConverter > getTypeConverter( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException);
612 diff --git vbahelper/source/vbahelper/vbaglobalbase.cxx vbahelper/source/vbahelper/vbaglobalbase.cxx
613 index 3ce0f72..bc0eda2 100644
614 --- vbahelper/source/vbahelper/vbaglobalbase.cxx
615 +++ vbahelper/source/vbahelper/vbaglobalbase.cxx
616 @@ -41,28 +41,41 @@
617 using namespace com::sun::star;
618 using namespace ooo::vba;
620 +rtl::OUString sApplication( RTL_CONSTASCII_USTRINGPARAM("Application") );
622 VbaGlobalsBase::VbaGlobalsBase(
623 const uno::Reference< ov::XHelperInterface >& xParent,
624 -const uno::Reference< uno::XComponentContext >& xContext)
625 +const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sDocCtxName )
626 : Globals_BASE( xParent, xContext )
628 // overwrite context with custom one ( that contains the application )
629 ::cppu::ContextEntry_Init aHandlerContextInfo[] =
631 - ::cppu::ContextEntry_Init( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Application" ) ), uno::Any() )
632 + ::cppu::ContextEntry_Init( sApplication, uno::Any() ),
633 + ::cppu::ContextEntry_Init( sDocCtxName, uno::Any() ),
636 mxContext = ::cppu::createComponentContext( aHandlerContextInfo, sizeof( aHandlerContextInfo ) / sizeof( aHandlerContextInfo[0] ), xContext );
641 void
642 -VbaGlobalsBase::init( uno::Reference< uno::XComponentContext >const& rxContext, const uno::Any& aApplication )
643 +VbaGlobalsBase::init( const uno::Sequence< beans::PropertyValue >& aInitArgs )
645 - uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY_THROW );
646 - xNameContainer->replaceByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Application") ), aApplication );
647 - uno::Reference< XHelperInterface > xParent( aApplication, uno::UNO_QUERY );
648 + sal_Int32 nLen = aInitArgs.getLength();
649 + for ( sal_Int32 nIndex = 0; nIndex < nLen; ++nIndex )
651 + uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY_THROW );
652 + if ( aInitArgs[ nIndex ].Name.equals( sApplication ) )
654 + xNameContainer->replaceByName( sApplication, aInitArgs[ nIndex ].Value );
655 + uno::Reference< XHelperInterface > xParent( aInitArgs[ nIndex ].Value, uno::UNO_QUERY );
656 mxParent = xParent;
658 + else
659 + xNameContainer->replaceByName( aInitArgs[ nIndex ].Name, aInitArgs[ nIndex ].Value );
663 uno::Reference< uno::XInterface > SAL_CALL
664 diff --git vbahelper/source/vbahelper/vbahelper.cxx vbahelper/source/vbahelper/vbahelper.cxx
665 index 8290f66..110d15f 100644
666 --- vbahelper/source/vbahelper/vbahelper.cxx
667 +++ vbahelper/source/vbahelper/vbahelper.cxx
668 @@ -458,19 +458,46 @@ getCurrentDoc( const rtl::OUString& sKey ) throw (uno::RuntimeException)
669 return xModel;
672 + uno::Reference< frame::XModel >
673 +getCurrentDocCtx( const rtl::OUString& ctxName, const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
675 + uno::Reference< frame::XModel > xModel;
676 + // try fallback to calling doc
677 + css::uno::Reference< css::container::XNameAccess > xNameAccess( xContext, css::uno::UNO_QUERY_THROW );
678 + xModel.set( xNameAccess->getByName( ctxName ), uno::UNO_QUERY_THROW );
679 + return xModel;
682 uno::Reference< frame::XModel >
683 -getCurrentExcelDoc() throw (uno::RuntimeException)
684 +getCurrentExcelDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
686 - static const rtl::OUString sThisExcelDoc( RTL_CONSTASCII_USTRINGPARAM("ThisExcelDoc" ) );
687 - return getCurrentDoc( sThisExcelDoc );
688 + static const rtl::OUString sThisExcelDoc( RTL_CONSTASCII_USTRINGPARAM("ThisExcelDoc" ) );
689 + uno::Reference< frame::XModel > xModel;
690 + try
692 + xModel = getCurrentDoc( sThisExcelDoc );
694 + catch( uno::Exception& e )
696 + xModel = getCurrentDocCtx( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ExcelDocumentContext" ) ), xContext );
698 + return xModel;
701 uno::Reference< frame::XModel >
702 -getCurrentWordDoc() throw (uno::RuntimeException)
703 +getCurrentWordDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
705 - static const rtl::OUString sThisWordDoc( RTL_CONSTASCII_USTRINGPARAM("ThisWordDoc" ) );
706 - return getCurrentDoc( sThisWordDoc );
707 + static const rtl::OUString sThisWordDoc( RTL_CONSTASCII_USTRINGPARAM("ThisWordDoc" ) );
708 + uno::Reference< frame::XModel > xModel;
709 + try
711 + xModel = getCurrentDoc( sThisWordDoc );
713 + catch( uno::Exception& e )
715 + xModel = getCurrentDocCtx( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WordDocumentContext" ) ), xContext );
717 + return xModel;
720 sal_Int32
721 diff --git sc/source/ui/docshell/docsh.cxx sc/source/ui/docshell/docsh.cxx
722 index 337ceb3..72d92cf 100644
723 --- sc/source/ui/docshell/docsh.cxx
724 +++ sc/source/ui/docshell/docsh.cxx
725 @@ -376,7 +376,9 @@ void ScDocShell::AfterXMLLoading(sal_Bool bRet)
726 if ( pShell )
728 uno::Any aGlobs;
729 - aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.Globals" ) ) );
730 + uno::Sequence< uno::Any > aArgs(1);
731 + aArgs[ 0 ] <<= pShell->GetModel();
732 + aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.Globals" ) ), aArgs );
733 pShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", aGlobs );
735 // suppress VBA events when loading the xml