1 diff --git sc/source/filter/excel/xlescher.cxx sc/source/filter/excel/xlescher.cxx
2 index 2109a0a..88eb9d0 100644
3 --- sc/source/filter/excel/xlescher.cxx
4 +++ sc/source/filter/excel/xlescher.cxx
6 #include <basic/sbmod.hxx>
7 #include <basic/sbmeth.hxx>
8 #include <basic/basmgr.hxx>
9 +#include <svx/msvbahelper.hxx>
11 using ::rtl::OUString;
12 using ::com::sun::star::uno::Reference;
13 @@ -306,7 +307,6 @@ Reference< XControlModel > XclControlHelper::GetControlModel( Reference< XShape
16 #define EXC_MACRONAME_PRE "vnd.sun.star.script:Standard."
17 -#define EXC_MACRO_SCHEME "vnd.sun.star.script:"
18 #define EXC_MACRONAME_SUF "?language=Basic&location=document"
20 OUString XclControlHelper::GetScMacroName( const String& rXclMacroName, SfxObjectShell* pDocShell )
21 @@ -314,27 +314,10 @@ OUString XclControlHelper::GetScMacroName( const String& rXclMacroName, SfxObjec
22 String sTmp( rXclMacroName );
23 if( rXclMacroName.Len() > 0 )
25 - String sProjectName( RTL_CONSTASCII_USTRINGPARAM("Standard") );
26 + ooo::vba::VBAMacroResolvedInfo aMacro = ooo::vba::resolveVBAMacro( pDocShell, rXclMacroName, false );
27 + if ( aMacro.IsResolved() )
28 + return ooo::vba::makeMacroURL( aMacro.ResolvedMacro() );
30 - if ( pDocShell && pDocShell->GetBasicManager()->GetName().Len() > 0 )
31 - sProjectName = pDocShell->GetBasicManager()->GetName();
33 - if ( ( sTmp.Search( '.' ) == STRING_NOTFOUND) && pDocShell )
35 - if( StarBASIC* pBasic = pDocShell->GetBasicManager()->GetLib( sProjectName ) )
37 - if( SbMethod* pMethod = dynamic_cast< SbMethod* >( pBasic->Find( sTmp, SbxCLASS_METHOD ) ) )
39 - if( SbModule* pModule = pMethod->GetModule() )
41 - sTmp.Insert( '.', 0 ).Insert( pModule->GetName(), 0 );
46 - sProjectName.Append( '.' );
47 - sTmp.Insert( sProjectName, 0 );
48 - return CREATE_OUSTRING( EXC_MACRO_SCHEME ) + sTmp + CREATE_OUSTRING( EXC_MACRONAME_SUF );
52 diff --git sc/source/ui/unoobj/docuno.cxx sc/source/ui/unoobj/docuno.cxx
53 index af78648..16a1c03 100644
54 --- sc/source/ui/unoobj/docuno.cxx
55 +++ sc/source/ui/unoobj/docuno.cxx
56 @@ -1793,6 +1793,12 @@ sal_Int64 SAL_CALL ScModelObj::getSomething(
57 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
60 + if ( rId.getLength() == 16 &&
61 + 0 == rtl_compareMemory( SfxObjectShell::getUnoTunnelId().getConstArray(),
62 + rId.getConstArray(), 16 ) )
64 + return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pDocShell ));
66 // aggregated number formats supplier has XUnoTunnel, too
67 // interface from aggregated object must be obtained via queryAggregation
69 diff --git sc/source/ui/vba/vbaeventshelper.cxx sc/source/ui/vba/vbaeventshelper.cxx
70 index 3948ac6..36e1115 100644
71 --- sc/source/ui/vba/vbaeventshelper.cxx
72 +++ sc/source/ui/vba/vbaeventshelper.cxx
73 @@ -614,8 +614,8 @@ rtl::OUString
74 ScVbaEventsHelper::getMacroPath( const sal_Int32 nEventId, const SCTAB nTab )
76 SfxObjectShell* pShell = pDoc->GetDocumentShell();
77 - rtl::OUString sMacroPath;
78 - rtl::OUString sMacroName = getEventName( nEventId );
79 + String sMacroName = getEventName( nEventId );
80 + VBAMacroResolvedInfo sMacroResolvedInfo;
84 @@ -629,8 +629,9 @@ ScVbaEventsHelper::getMacroPath( const sal_Int32 nEventId, const SCTAB nTab )
85 case VBAEVENT_WORKSHEET_PIVOTTABLEUPDATE :
86 case VBAEVENT_WORKSHEET_SELECTIONCHANGE :
88 - rtl::OUString aSheetModuleName = getSheetModuleName( nTab );
89 - sMacroPath = findVBAMacro( pShell, aSheetModuleName, sMacroName );
90 + String aSheetModuleName = getSheetModuleName( nTab );
91 + sMacroName.Insert( '.', 0 ).Insert( aSheetModuleName, 0);
92 + sMacroResolvedInfo = resolveVBAMacro( pShell, sMacroName );
96 @@ -664,13 +665,14 @@ ScVbaEventsHelper::getMacroPath( const sal_Int32 nEventId, const SCTAB nTab )
97 sWorkbookModuleName = aExtDocSettings.maGlobCodeName;
100 - sMacroPath = findVBAMacro( pShell, sWorkbookModuleName, sMacroName );
101 + sMacroName.Insert( '.', 0 ).Insert( sWorkbookModuleName, 0);
102 + sMacroResolvedInfo = resolveVBAMacro( pShell, sMacroName );
109 + return sMacroResolvedInfo.ResolvedMacro();
112 sal_Bool ScVbaEventsHelper::processVbaEvent( const sal_Int32 nEventId, const uno::Sequence< uno::Any >& rArgs, const SCTAB nTab )
113 @@ -681,6 +683,7 @@ sal_Bool ScVbaEventsHelper::processVbaEvent( const sal_Int32 nEventId, const uno
114 sal_Bool bCancel = sal_False;
115 uno::Sequence< uno::Any > aArgs;
117 + uno::Any aDummyCaller;
119 // For most cases, there is no corresponsible event macro in the document.
120 // It is better fo check if the event macro exists before process the arguments to improve performance.
121 @@ -777,7 +780,7 @@ sal_Bool ScVbaEventsHelper::processVbaEvent( const sal_Int32 nEventId, const uno
122 // process Cancel argument
123 aArgs = uno::Sequence< uno::Any >(1);
124 aArgs[0] <<= bCancel;
125 - executeMacro( pShell, sMacroPath, aArgs, aRet );
126 + executeMacro( pShell, sMacroPath, aArgs, aRet, aDummyCaller );
127 aArgs[0] >>= bCancel;
130 @@ -787,7 +790,7 @@ sal_Bool ScVbaEventsHelper::processVbaEvent( const sal_Int32 nEventId, const uno
131 aArgs = uno::Sequence< uno::Any >(2);
133 aArgs[1] <<= bCancel;
134 - executeMacro( pShell, sMacroPath, aArgs, aRet );
135 + executeMacro( pShell, sMacroPath, aArgs, aRet, aDummyCaller );
136 aArgs[1] >>= bCancel;
139 @@ -805,7 +808,7 @@ sal_Bool ScVbaEventsHelper::processVbaEvent( const sal_Int32 nEventId, const uno
143 - result = executeMacro( pShell, sMacroPath, aArgs, aRet );
144 + result = executeMacro( pShell, sMacroPath, aArgs, aRet, aDummyCaller );
148 diff --git scripting/prj/build.lst scripting/prj/build.lst
149 index fc33238..f216009 100644
150 --- scripting/prj/build.lst
151 +++ scripting/prj/build.lst
153 -tc scripting : oovbaapi bridges rdbmaker vcl xmlscript basic sfx2 rhino BSH:beanshell javaunohelper NULL
154 +tc scripting : oovbaapi svx bridges rdbmaker vcl xmlscript basic sfx2 rhino BSH:beanshell javaunohelper NULL
155 tc scripting usr1 - all tc1_mkout NULL
156 tc scripting\inc nmake - all tc1_inc NULL
157 tc scripting\source\provider nmake - all tc1_scriptingprovider tc1_inc NULL
158 diff --git scripting/source/vbaevents/eventhelper.cxx scripting/source/vbaevents/eventhelper.cxx
159 index 84dc900..f85ac51 100644
160 --- scripting/source/vbaevents/eventhelper.cxx
161 +++ scripting/source/vbaevents/eventhelper.cxx
163 #include <basic/sbmeth.hxx>
164 #include <basic/sbmod.hxx>
165 #include <basic/sbx.hxx>
169 +#include <svx/msvbahelper.hxx>
172 #include <comphelper/anytostring.hxx>
175 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
176 #include <com/sun/star/script/XScriptListener.hpp>
177 #include <cppuhelper/implbase1.hxx>
178 @@ -771,7 +768,7 @@ EventListener::getPropertySetInfo( ) throw (RuntimeException)
182 -EventListener::firing_Impl(const ScriptEvent& evt, Any* /*pRet*/ ) throw(RuntimeException)
183 +EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) throw(RuntimeException)
185 OSL_TRACE("EventListener::firing_Impl( FAKE VBA_EVENTS )");
186 static const ::rtl::OUString vbaInterOp =
187 @@ -842,22 +839,16 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* /*pRet*/ ) throw(Runtime
188 sMacroLoc = sMacroLoc.concat( sScriptCode ).concat( rtl::OUString::createFromAscii(".") );
190 OSL_TRACE("sMacroLoc is %s", rtl::OUStringToOString( sMacroLoc, RTL_TEXTENCODING_UTF8 ).getStr() );
193 - pBasic = pBasicManager->GetLib( sProject );
195 - SbModule* pModule = pBasic ? pBasic->FindModule( sScriptCode ) : NULL;
197 - for ( ; pModule && txInfo != txInfo_end; ++txInfo )
198 + for ( ; txInfo != txInfo_end; ++txInfo )
200 + rtl::OUString sTemp = sName.concat( (*txInfo).sVBAName );
201 // see if we have a match for the handlerextension
202 // where ScriptCode is methodname_handlerextension
203 - rtl::OUString sTemp = sName.concat( (*txInfo).sVBAName );
205 + rtl::OUString sToResolve = sMacroLoc.concat( sTemp );
206 OSL_TRACE("*** trying to invoke %s ",
207 - rtl::OUStringToOString( sTemp, RTL_TEXTENCODING_UTF8 ).getStr() );
208 - SbMethod* pMeth = static_cast< SbMethod* >( pModule->Find( sTemp, SbxCLASS_METHOD ) );
210 + rtl::OUStringToOString( sToResolve, RTL_TEXTENCODING_UTF8 ).getStr() );
211 + ooo::vba::VBAMacroResolvedInfo aMacroResolvedInfo = ooo::vba::resolveVBAMacro( mpShell, sToResolve );
212 + if ( aMacroResolvedInfo.IsResolved() )
214 // !! translate arguments & emulate events where necessary
215 Sequence< Any > aArguments;
216 @@ -869,31 +860,22 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* /*pRet*/ ) throw(Runtime
218 // call basic event handlers for event
220 - static rtl::OUString part1 = rtl::OUString::createFromAscii( "vnd.sun.star.script:");
221 - static rtl::OUString part2 = rtl::OUString::createFromAscii("?language=Basic&location=document");
224 - rtl::OUString url = part1 + sMacroLoc + sTemp + part2;
225 + rtl::OUString url = aMacroResolvedInfo.ResolvedMacro();
227 - OSL_TRACE("script url = %s",
228 + OSL_TRACE("resolved script = %s",
229 rtl::OUStringToOString( url,
230 RTL_TEXTENCODING_UTF8 ).getStr() );
231 - Sequence< sal_Int16 > aOutArgsIndex;
232 - Sequence< Any > aOutArgs;
235 - uno::Reference< script::provider::XScript > xScript = xScriptProvider->getScript( url );
236 - if ( xScript.is() )
238 - uno::Reference< beans::XPropertySet > xProps( xScript, uno::UNO_QUERY );
241 - Sequence< Any > aCallerHack(1);
242 - aCallerHack[ 0 ] = uno::makeAny( rtl::OUString::createFromAscii("Error") );
243 - xProps->setPropertyValue( rtl::OUString::createFromAscii( "Caller" ), uno::makeAny( aCallerHack ) );
245 - xScript->invoke( aArguments, aOutArgsIndex, aOutArgs );
247 + uno::Any aDummyCaller = uno::makeAny( rtl::OUString::createFromAscii("Error") );
249 + ooo::vba::executeMacro( mpShell, url, aArguments, *pRet, aDummyCaller );
253 + ooo::vba::executeMacro( mpShell, url, aArguments, aRet, aDummyCaller );
256 catch ( uno::Exception& e )
258 diff --git scripting/source/vbaevents/makefile.mk scripting/source/vbaevents/makefile.mk
259 index eabb67e..96f4e3d 100644
260 --- scripting/source/vbaevents/makefile.mk
261 +++ scripting/source/vbaevents/makefile.mk
262 @@ -46,6 +46,7 @@ SHL1STDLIBS= \
266 + $(SVXMSFILTERLIB) \
270 diff --git sfx2/inc/sfx2/objsh.hxx sfx2/inc/sfx2/objsh.hxx
271 index c65280b..3f2d197 100644
272 --- sfx2/inc/sfx2/objsh.hxx
273 +++ sfx2/inc/sfx2/objsh.hxx
274 @@ -265,6 +265,7 @@ public:
276 SFX_DECL_INTERFACE(SFX_INTERFACE_SFXDOCSH)
278 + static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
279 /* Stampit disable/enable cancel button for print jobs
280 default = true = enable! */
281 void Stamp_SetPrintCancelState(sal_Bool bState);
282 @@ -885,6 +886,7 @@ public:
283 virtual sal_Bool PutValue( const com::sun::star::uno::Any& rVal, BYTE nMemberId = 0 );
284 SfxObjectShell* GetObjectShell() const
290 diff --git sfx2/source/doc/objserv.cxx sfx2/source/doc/objserv.cxx
291 index d16f0c8..dd4f044 100644
292 --- sfx2/source/doc/objserv.cxx
293 +++ sfx2/source/doc/objserv.cxx
294 @@ -1480,3 +1480,19 @@ void SfxObjectShell::SignScriptingContent()
299 +const uno::Sequence<sal_Int8>& SfxObjectShell::getUnoTunnelId()
301 + static uno::Sequence<sal_Int8> * pSeq = 0;
304 + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
307 + static uno::Sequence< sal_Int8 > aSeq( 16 );
308 + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
314 diff --git svx/inc/svx/mstoolbar.hxx svx/inc/svx/mstoolbar.hxx
315 index b3667a8..5d76eaf 100644
316 --- svx/inc/svx/mstoolbar.hxx
317 +++ svx/inc/svx/mstoolbar.hxx
318 @@ -55,6 +55,7 @@ public:
320 rtl::OUString MSOCommandToOOCommand( sal_Int16 msoCmd );
321 rtl::OUString MSOTCIDToOOCommand( sal_Int16 msoTCID );
322 + SfxObjectShell& GetDocShell() { return mrDocSh; }
325 class SVX_DLLPUBLIC TBBase
326 diff --git svx/inc/svx/msvbahelper.hxx svx/inc/svx/msvbahelper.hxx
327 index 8be6901..294f26e 100644
328 --- svx/inc/svx/msvbahelper.hxx
329 +++ svx/inc/svx/msvbahelper.hxx
332 namespace ooo { namespace vba
334 + class SVX_DLLPUBLIC VBAMacroResolvedInfo
336 + SfxObjectShell* mpDocContext;
338 + String msResolvedMacro;
340 + VBAMacroResolvedInfo() : mpDocContext(NULL), mbFound( false ){}
341 + void SetResolved( bool bRes ) { mbFound = bRes; }
342 + bool IsResolved() { return mbFound; }
343 + void SetMacroDocContext(SfxObjectShell* pShell ) { mpDocContext = pShell; }
344 + SfxObjectShell* MacroDocContext() { return mpDocContext; }
345 + String ResolvedMacro() { return msResolvedMacro; }
346 + void SetResolvedMacro(const String& sMacro ) { msResolvedMacro = sMacro; }
349 SVX_DLLPUBLIC String makeMacroURL( const String& sMacroName );
350 - SVX_DLLPUBLIC String findVBAMacro( SfxObjectShell* pShell, const String& sMod, const String& sMacro );
351 - SVX_DLLPUBLIC sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArgs, com::sun::star::uno::Any& aRet );
352 + SVX_DLLPUBLIC VBAMacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& sMod, bool bSearchGlobalTemplates = false );
353 + SVX_DLLPUBLIC sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArgs, com::sun::star::uno::Any& aRet, const com::sun::star::uno::Any& aCaller );
357 diff --git svx/inc/svxmsbas.hxx svx/inc/svxmsbas.hxx
358 index a777795..fab5faf 100644
359 --- svx/inc/svxmsbas.hxx
360 +++ svx/inc/svxmsbas.hxx
361 @@ -91,6 +91,7 @@ public:
362 static ULONG GetSaveWarningOfMSVBAStorage( SfxObjectShell &rDocS );
364 static String GetMSBasicStorageName();
365 + rtl::OUString GetVBAProjectName() { return msProjectName; }
368 SfxObjectShell &rDocSh;
369 diff --git svx/source/msfilter/mstoolbar.cxx svx/source/msfilter/mstoolbar.cxx
370 index 9579db7..fa66fe5 100644
371 --- svx/source/msfilter/mstoolbar.cxx
372 +++ svx/source/msfilter/mstoolbar.cxx
374 #include <basic/basmgr.hxx>
375 #include <svtools/filterutils.hxx>
376 #include <boost/scoped_array.hpp>
377 +#include <svx/msvbahelper.hxx>
379 int TBBase::nIndent = 0;
381 @@ -67,16 +68,8 @@ CustomToolBarImportHelper::createCommandFromMacro( const rtl::OUString& sCmd )
382 //"vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=document"
383 static rtl::OUString scheme = rtl::OUString::createFromAscii( "vnd.sun.star.script:");
384 static rtl::OUString part2 = rtl::OUString::createFromAscii("?language=Basic&location=document");
385 - rtl::OUString sProject( RTL_CONSTASCII_USTRINGPARAM("Standard") );
386 - if ( mrDocSh.GetBasicManager()->GetName().Len() )
387 - sProject = mrDocSh.GetBasicManager()->GetName();
388 - sProject += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".") );
390 - // #TODO #FIXME a script can also be loosly defined ( e.g. with no module
394 - rtl::OUString scriptURL = scheme + sProject + sCmd + part2;
395 + rtl::OUString scriptURL = scheme + sCmd + part2;
396 return uno::makeAny( scriptURL );
399 @@ -377,7 +370,9 @@ TBCGeneralInfo::ImportToolBarControlData( CustomToolBarImportHelper& helper, std
400 if ( extraInfo.getOnAction().getLength() )
402 aProp.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CommandURL") );
403 - aProp.Value = helper.createCommandFromMacro( extraInfo.getOnAction() );
404 + ooo::vba::VBAMacroResolvedInfo aMacroInf = ooo::vba::resolveVBAMacro( &helper.GetDocShell(), extraInfo.getOnAction(), true );
405 + if ( aMacroInf.IsResolved() )
406 + aProp.Value = helper.createCommandFromMacro( aMacroInf.ResolvedMacro() );
407 sControlData.push_back( aProp );
410 @@ -390,7 +385,7 @@ TBCGeneralInfo::ImportToolBarControlData( CustomToolBarImportHelper& helper, std
411 sControlData.push_back( aProp );
413 aProp.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HelpURL") );
414 - aProp.Value = uno::makeAny( helper.createCommandFromMacro( tooltip.getString() ) );
415 + aProp.Value = uno::makeAny( tooltip.getString() );
416 sControlData.push_back( aProp );
418 // #TODO find out what is the property for tooltip?
419 diff --git svx/source/msfilter/msvbahelper.cxx svx/source/msfilter/msvbahelper.cxx
420 index 5875cf7..d02746f 100644
421 --- svx/source/msfilter/msvbahelper.cxx
422 +++ svx/source/msfilter/msvbahelper.cxx
424 #include <basic/basmgr.hxx>
425 #include <basic/sbmod.hxx>
426 #include <basic/sbmeth.hxx>
427 +#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
428 +#include <com/sun/star/document/XDocumentProperties.hpp>
429 +#include <com/sun/star/document/XDocumentInfoSupplier.hpp>
430 +#include <tools/urlobj.hxx>
431 +#include <osl/file.hxx>
433 using namespace ::com::sun::star;
435 @@ -44,91 +49,335 @@ namespace ooo { namespace vba {
437 String makeMacroURL( const String& sMacroName )
439 - return sUrlPart0.concat( sMacroName ).concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".") ) ).concat( sUrlPart1 ) ;
440 + return sUrlPart0.concat( sMacroName ).concat( sUrlPart1 ) ;
443 -String findVBAMacro( SfxObjectShell* pShell, const String& sMod, const String& sMacro )
444 +SfxObjectShell* findShellForUrl( const rtl::OUString& sMacroURLOrPath )
447 - // would use the script provider to see if the macro exists but
448 - // called at this stage tdoc content handler stuff is not set up
451 - String sLibrary( RTL_CONSTASCII_USTRINGPARAM("Standard"));
452 - BasicManager* pBasicMgr = pShell-> GetBasicManager();
455 - if ( pBasicMgr->GetName().Len() )
456 - sLibrary = pBasicMgr->GetName();
457 - StarBASIC* pBasic = pBasicMgr->GetLib( sLibrary );
460 - USHORT nId = pBasicMgr->GetLibId( sLibrary );
461 - pBasicMgr->LoadLib( nId );
462 - pBasic = pBasicMgr->GetLib( sLibrary );
466 - if ( sMod.Len() ) // we wish to find the macro is a specific module
468 - SbModule* pModule = pBasic->FindModule( sMod );
471 - SbxArray* pMethods = pModule->GetMethods();
474 - SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Find( sMacro, SbxCLASS_METHOD ) );
477 - sFullName = sMacro;
478 - sFullName.Insert( '.', 0 ).Insert( sMod, 0 ).Insert( '.', 0 ).Insert( sLibrary, 0 );
483 - else if( SbMethod* pMethod = dynamic_cast< SbMethod* >( pBasic->Find( sMacro, SbxCLASS_METHOD ) ) )
485 - if( SbModule* pModule = pMethod->GetModule() )
487 - sFullName = sMacro;
488 - sFullName.Insert( '.', 0 ).Insert( pModule->GetName(), 0).Insert( '.', 0 ).Insert( sLibrary, 0 );
495 + SfxObjectShell* pFoundShell=NULL;
496 + SfxObjectShell* pShell = SfxObjectShell::GetFirst();
497 + INetURLObject aObj;
498 + aObj.SetURL( sMacroURLOrPath );
499 + bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID;
500 + rtl::OUString aURL;
502 + aURL = sMacroURLOrPath;
505 + osl::FileBase::getFileURLFromSystemPath( sMacroURLOrPath, aURL );
506 + aObj.SetURL( aURL );
508 + OSL_TRACE("Trying to find shell for url %s", rtl::OUStringToOString( aURL, RTL_TEXTENCODING_UTF8 ).getStr() );
512 + uno::Reference< frame::XModel > xModel = pShell->GetModel();
513 + // are we searching for a template? if so we have to cater for the
514 + // fact that in openoffice a document opened from a template is always
515 + // a new document :/
518 + OSL_TRACE("shell 0x%x has model with url %s and we look for %s", pShell
519 + , rtl::OUStringToOString( xModel->getURL(), RTL_TEXTENCODING_UTF8 ).getStr()
520 + , rtl::OUStringToOString( aURL, RTL_TEXTENCODING_UTF8 ).getStr()
522 + if ( sMacroURLOrPath.endsWithIgnoreAsciiCaseAsciiL( ".dot", 4 ) )
524 + uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( xModel, uno::UNO_QUERY );
525 + if( xDocInfoSupp.is() )
527 + uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW );
528 + uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW );
529 + rtl::OUString sCurrName = xDocProps->getTemplateName();
530 + if( sMacroURLOrPath.lastIndexOf( sCurrName ) >= 0 )
532 + pFoundShell = pShell;
539 + if ( aURL.equals( xModel->getURL() ) )
541 + pFoundShell = pShell;
546 + pShell = SfxObjectShell::GetNext( *pShell );
548 + return pFoundShell;
551 -// Treat the args as possible inouts ( convertion at bottom of method )
552 -sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, uno::Sequence< uno::Any >& aArgs, uno::Any& aRet )
553 +// sMod can be empty ( but we really need the library to search in )
554 +// if sMod is empty and a macro is found then sMod is updated
555 +bool hasMacro( SfxObjectShell* pShell, const String& sLibrary, String& sMod, const String& sMacro )
557 + bool bFound = false;
558 + if ( sLibrary.Len() && sMacro.Len() )
560 + OSL_TRACE("** Searching for %s.%s in library %s"
561 + ,rtl::OUStringToOString( sMod, RTL_TEXTENCODING_UTF8 ).getStr()
562 + ,rtl::OUStringToOString( sMacro, RTL_TEXTENCODING_UTF8 ).getStr()
563 + ,rtl::OUStringToOString( sLibrary, RTL_TEXTENCODING_UTF8 ).getStr() );
564 + BasicManager* pBasicMgr = pShell-> GetBasicManager();
567 + StarBASIC* pBasic = pBasicMgr->GetLib( sLibrary );
570 + USHORT nId = pBasicMgr->GetLibId( sLibrary );
571 + pBasicMgr->LoadLib( nId );
572 + pBasic = pBasicMgr->GetLib( sLibrary );
576 + if ( sMod.Len() ) // we wish to find the macro is a specific module
578 + SbModule* pModule = pBasic->FindModule( sMod );
581 + SbxArray* pMethods = pModule->GetMethods();
584 + SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Find( sMacro, SbxCLASS_METHOD ) );
590 + else if( SbMethod* pMethod = dynamic_cast< SbMethod* >( pBasic->Find( sMacro, SbxCLASS_METHOD ) ) )
592 + if( SbModule* pModule = pMethod->GetModule() )
594 + sMod = pModule->GetName();
603 +void parseMacro( const rtl::OUString& sMacro, String& sContainer, String& sModule, String& sProcedure )
605 - // until ObjectModules ( and persisting of codenames ) is supported, if this is a
606 - // document saved from XL then we won't be able to determine the codename for the Workbook
607 - // Module, so... we have no choice but to search all modules for the moment, thus the macro
608 - // passed in should be the fully specified name.
609 - rtl::OUString sUrl = makeMacroURL( sMacroName );
610 - uno::Sequence< sal_Int16 > aOutArgsIndex;
611 - uno::Sequence< uno::Any > aOutArgs;
612 - ErrCode nErr = pShell->CallXScript( sUrl, aArgs, aRet,
613 - aOutArgsIndex, aOutArgs, sal_False );
615 - // Script Executed?
616 - if ( nErr != ERRCODE_NONE )
619 - sal_Int32 nLen = aOutArgs.getLength();
620 - // convert any out params to seem like they were inouts
623 - for ( sal_Int32 index=0; index < nLen; ++index )
625 - sal_Int32 nOutIndex = aOutArgsIndex[ index ];
626 - aArgs[ nOutIndex ] = aOutArgs[ index ];
631 + sal_Int32 nMacroDot = sMacro.lastIndexOf( '.' );
633 + if ( nMacroDot != -1 )
635 + sProcedure = sMacro.copy( nMacroDot + 1 );
637 + sal_Int32 nContainerDot = sMacro.lastIndexOf( '.', nMacroDot - 1 );
638 + if ( nContainerDot != -1 )
640 + sModule = sMacro.copy( nContainerDot + 1, nMacroDot - nContainerDot - 1 );
641 + sContainer = sMacro.copy( 0, nContainerDot );
644 + sModule = sMacro.copy( 0, nMacroDot );
647 + sProcedure = sMacro;
650 +VBAMacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& MacroName, bool bSearchGlobalTemplates )
652 + VBAMacroResolvedInfo aRes;
655 + aRes.SetMacroDocContext( pShell );
656 + // parse the macro name
657 + sal_Int32 nDocSepIndex = MacroName.indexOfAsciiL( "!", 1 );
658 + String sMacroUrl = MacroName;
664 + if( nDocSepIndex > 0 )
666 + // macro specified by document name
667 + // find document shell for document name and call ourselves
670 + // assume for now that the document name is *this* document
671 + String sDocUrlOrPath = MacroName.copy( 0, nDocSepIndex );
672 + sMacroUrl = MacroName.copy( nDocSepIndex + 1 );
673 + OSL_TRACE("doc search, current shell is 0x%x", pShell );
674 + SfxObjectShell* pFoundShell = findShellForUrl( sDocUrlOrPath );
675 + OSL_TRACE("doc search, after find, found shell is 0x%x", pFoundShell );
676 + aRes = resolveVBAMacro( pFoundShell, sMacroUrl );
680 + // macro is contained in 'this' document ( or code imported from a template
681 + // where that template is a global template or perhaps the template this
682 + // document is created from )
684 + // macro format = Container.Module.Procedure
685 + parseMacro( MacroName, sContainer, sModule, sProcedure );
686 + uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY);
687 + uno::Reference< container::XNameContainer > xPrjNameCache;
689 + xPrjNameCache.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAProjectNameProvider" ) ) ), uno::UNO_QUERY );
691 + std::vector< rtl::OUString > sSearchList;
693 + if ( sContainer.Len() > 0 )
695 + // get the Project associated with the Container
696 + if ( xPrjNameCache.is() )
698 + if ( xPrjNameCache->hasByName( sContainer ) )
700 + rtl::OUString sProject;
701 + xPrjNameCache->getByName( sContainer ) >>= sProject;
702 + sContainer = sProject;
705 + sSearchList.push_back( sContainer ); // First Lib to search
709 + // Ok, if we have no Container specified then we need to search them in order, this document, template this document created from, global templates,
710 + // get the name of Project/Library for 'this' document
711 + rtl::OUString sThisProject;
712 + BasicManager* pBasicMgr = pShell-> GetBasicManager();
715 + if ( pBasicMgr->GetName().Len() )
716 + sThisProject = pBasicMgr->GetName();
717 + else // cater for the case where VBA is not enabled
718 + sThisProject = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") );
720 + sSearchList.push_back( sThisProject ); // First Lib to search
721 + if ( xPrjNameCache.is() )
723 + // is this document created from a template?
724 + uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( pShell->GetModel(), uno::UNO_QUERY_THROW );
725 + uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW );
726 + uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW );
728 + rtl::OUString sCreatedFrom = xDocProps->getTemplateURL();
729 + if ( sCreatedFrom.getLength() )
731 + INetURLObject aObj;
732 + aObj.SetURL( sCreatedFrom );
733 + bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID;
734 + rtl::OUString aURL;
736 + aURL = sCreatedFrom;
739 + osl::FileBase::getFileURLFromSystemPath( sCreatedFrom, aURL );
740 + aObj.SetURL( aURL );
742 + sCreatedFrom = aObj.GetLastName();
745 + sal_Int32 nIndex = sCreatedFrom.lastIndexOf( '.' );
746 + if ( nIndex != -1 )
747 + sCreatedFrom = sCreatedFrom.copy( 0, nIndex );
749 + rtl::OUString sPrj;
750 + if ( sCreatedFrom.getLength() && xPrjNameCache->hasByName( sCreatedFrom ) )
752 + xPrjNameCache->getByName( sCreatedFrom ) >>= sPrj;
753 + // Make sure we don't double up with this project
754 + if ( !sPrj.equals( sThisProject ) )
755 + sSearchList.push_back( sPrj );
758 + // get list of global template Names
759 + uno::Sequence< rtl::OUString > sTemplateNames = xPrjNameCache->getElementNames();
760 + sal_Int32 nLen = sTemplateNames.getLength();
761 + for ( sal_Int32 index = 0; ( bSearchGlobalTemplates && index < nLen ); ++index )
764 + if ( !sCreatedFrom.equals( sTemplateNames[ index ] ) )
766 + if ( xPrjNameCache->hasByName( sTemplateNames[ index ] ) )
768 + xPrjNameCache->getByName( sTemplateNames[ index ] ) >>= sPrj;
769 + // Make sure we don't double up with this project
770 + if ( !sPrj.equals( sThisProject ) )
771 + sSearchList.push_back( sPrj );
778 + std::vector< rtl::OUString >::iterator it_end = sSearchList.end();
779 + for ( std::vector< rtl::OUString >::iterator it = sSearchList.begin(); it != it_end; ++it )
781 + bool bRes = hasMacro( pShell, *it, sModule, sProcedure );
784 + aRes.SetResolved( true );
785 + aRes.SetMacroDocContext( pShell );
791 + aRes.SetResolvedMacro( sProcedure.Insert( '.', 0 ).Insert( sModule, 0).Insert( '.', 0 ).Insert( sContainer, 0 ) );
796 +// Treat the args as possible inouts ( convertion at bottom of method )
797 +sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, uno::Sequence< uno::Any >& aArgs, uno::Any& /*aRet*/, const uno::Any& aCaller )
799 + sal_Bool bRes = sal_False;
802 + rtl::OUString sUrl = makeMacroURL( sMacroName );
804 + uno::Sequence< sal_Int16 > aOutArgsIndex;
805 + uno::Sequence< uno::Any > aOutArgs;
809 + uno::Reference< script::provider::XScriptProvider > xScriptProvider;
810 + uno::Reference< script::provider::XScriptProviderSupplier > xSPS( pShell->GetModel(), uno::UNO_QUERY_THROW );
812 + xScriptProvider.set( xSPS->getScriptProvider(), uno::UNO_QUERY_THROW );
814 + uno::Reference< script::provider::XScript > xScript( xScriptProvider->getScript( sUrl ), uno::UNO_QUERY_THROW );
816 + if ( aCaller.hasValue() )
818 + uno::Reference< beans::XPropertySet > xProps( xScript, uno::UNO_QUERY );
821 + uno::Sequence< uno::Any > aCallerHack(1);
822 + aCallerHack[ 0 ] = aCaller;
823 + xProps->setPropertyValue( rtl::OUString::createFromAscii( "Caller" ), uno::makeAny( aCallerHack ) );
828 + xScript->invoke( aArgs, aOutArgsIndex, aOutArgs );
830 + sal_Int32 nLen = aOutArgs.getLength();
831 + // convert any out params to seem like they were inouts
834 + for ( sal_Int32 index=0; index < nLen; ++index )
836 + sal_Int32 nOutIndex = aOutArgsIndex[ index ];
837 + aArgs[ nOutIndex ] = aOutArgs[ index ];
843 + catch ( uno::Exception& e )
850 diff --git sw/inc/doc.hxx sw/inc/doc.hxx
851 index 5ee662e..68c5660 100644
854 @@ -417,6 +417,7 @@ class SW_DLLPUBLIC SwDoc :
856 // table of forbidden characters of this document
857 vos::ORef<SvxForbiddenCharactersTable> xForbiddenCharsTable;
858 + com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> m_xTemplateToProjectCache;
860 // --> OD 2007-10-26 #i83479#
862 @@ -2127,6 +2128,8 @@ public:
864 return n32DummyCompatabilityOptions2;
866 + void SetVBATemplateToProjectCache( com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >& xCache ) { m_xTemplateToProjectCache = xCache; };
867 + com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > GetVBATemplateToProjectCache() { return m_xTemplateToProjectCache; };
871 diff --git sw/inc/unocoll.hxx sw/inc/unocoll.hxx
872 index e9da66c..2c6bd02 100644
873 --- sw/inc/unocoll.hxx
874 +++ sw/inc/unocoll.hxx
875 @@ -197,8 +197,9 @@ class SwUnoCollection
876 #define SW_SERVICE_TYPE_FORMFIELDMARK 108
877 #define SW_SERVICE_VBAOBJECTPROVIDER 109
878 #define SW_SERVICE_VBACODENAMEPROVIDER 110
879 +#define SW_SERVICE_VBAPROJECTNAMEPROVIDER 111
881 -#define SW_SERVICE_LAST SW_SERVICE_VBACODENAMEPROVIDER
882 +#define SW_SERVICE_LAST SW_SERVICE_VBAPROJECTNAMEPROVIDER
884 #define SW_SERVICE_INVALID USHRT_MAX
886 diff --git sw/source/core/unocore/unocoll.cxx sw/source/core/unocore/unocoll.cxx
887 index 54797da..e3cded8 100644
888 --- sw/source/core/unocore/unocoll.cxx
889 +++ sw/source/core/unocore/unocoll.cxx
890 @@ -163,6 +163,71 @@ public:
894 +typedef std::hash_map< rtl::OUString, rtl::OUString, rtl::OUStringHash > StringHashMap;
895 +class SwVbaProjectNameProvider : public ::cppu::WeakImplHelper1< container::XNameContainer >
897 + SwDocShell* mpDocShell;
898 + StringHashMap mTemplateToProject;
900 + SwVbaProjectNameProvider( SwDocShell* pDocShell ) : mpDocShell( pDocShell )
903 + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException )
905 + return ( mTemplateToProject.find( aName ) != mTemplateToProject.end() );
907 + virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
909 + if ( !hasByName( aName ) )
910 + throw container::NoSuchElementException();
911 + return uno::makeAny( mTemplateToProject.find( aName )->second );
913 + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (::com::sun::star::uno::RuntimeException)
915 + uno::Sequence< rtl::OUString > aElements( mTemplateToProject.size() );
916 + StringHashMap::iterator it_end = mTemplateToProject.end();
917 + sal_Int32 index = 0;
918 + for ( StringHashMap::iterator it = mTemplateToProject.begin(); it != it_end; ++it, ++index )
919 + aElements[ index ] = it->first;
923 + virtual void SAL_CALL insertByName( const rtl::OUString& aName, const uno::Any& aElement ) throw ( com::sun::star::lang::IllegalArgumentException, com::sun::star::container::ElementExistException, com::sun::star::lang::WrappedTargetException )
926 + rtl::OUString sProjectName;
927 + aElement >>= sProjectName;
928 + OSL_TRACE("** Template cache inserting template name %s with project %s"
929 + , rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr()
930 + , rtl::OUStringToOString( sProjectName, RTL_TEXTENCODING_UTF8 ).getStr() );
931 + mTemplateToProject[ aName ] = sProjectName;
934 + virtual void SAL_CALL removeByName( const rtl::OUString& Name ) throw ( com::sun::star::container::NoSuchElementException, com::sun::star::lang::WrappedTargetException )
936 + if ( !hasByName( Name ) )
937 + throw container::NoSuchElementException();
938 + mTemplateToProject.erase( Name );
940 + virtual void SAL_CALL replaceByName( const rtl::OUString& aName, const uno::Any& aElement ) throw ( com::sun::star::lang::IllegalArgumentException, com::sun::star::container::NoSuchElementException, com::sun::star::lang::WrappedTargetException )
942 + if ( !hasByName( aName ) )
943 + throw container::NoSuchElementException();
944 + insertByName( aName, aElement ); // insert will overwrite
947 + virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException)
949 + return ::getCppuType((const rtl::OUString*)0);
951 + virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException )
954 + return ( mTemplateToProject.size() > 0 );
959 class SwVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
961 SwDocShell* mpDocShell;
962 @@ -325,6 +390,7 @@ const ProvNamesId_Type __FAR_DATA aProvNamesId[] =
963 { "com.sun.star.chart2.data.DataProvider", SW_SERVICE_CHART2_DATA_PROVIDER },
964 { "ooo.vba.VBAObjectModuleObjectProvider", SW_SERVICE_VBAOBJECTPROVIDER },
965 { "ooo.vba.VBACodeNameProvider", SW_SERVICE_VBACODENAMEPROVIDER },
966 + { "ooo.vba.VBAProjectNameProvider", SW_SERVICE_VBAPROJECTNAMEPROVIDER },
968 // case-correct versions of the service names (see #i67811)
969 { CSS_TEXT_TEXTFIELD_DATE_TIME, SW_SERVICE_FIELDTYPE_DATETIME },
970 @@ -517,6 +583,18 @@ uno::Reference< uno::XInterface > SwXServiceProvider::MakeInstance(sal_uInt16
971 xRet = (cppu::OWeakObject*)pObjProv;
974 + case SW_SERVICE_VBAPROJECTNAMEPROVIDER :
976 + uno::Reference< container::XNameContainer > xProjProv = pDoc->GetVBATemplateToProjectCache();
977 + if ( !xProjProv.is() )
979 + xProjProv = new SwVbaProjectNameProvider( pDoc->GetDocShell() );
980 + pDoc->SetVBATemplateToProjectCache( xProjProv );
982 + //xRet = (cppu::OWeakObject*)xProjProv;
986 case SW_SERVICE_TYPE_FOOTNOTE :
987 xRet = (cppu::OWeakObject*)new SwXFootnote(sal_False);
989 diff --git sw/source/filter/ww8/ww8par.cxx sw/source/filter/ww8/ww8par.cxx
990 index 90efd7b..e1366a2 100644
991 --- sw/source/filter/ww8/ww8par.cxx
992 +++ sw/source/filter/ww8/ww8par.cxx
993 @@ -161,7 +161,7 @@ using namespace nsHdFtFlags;
994 #include <svtools/pathoptions.hxx>
995 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
997 -const static String sModule( RTL_CONSTASCII_USTRINGPARAM("ThisDocument"));
998 +const static String sThisDocument( RTL_CONSTASCII_USTRINGPARAM("ThisDocument"));
1000 struct DocEventNameTable
1002 @@ -191,10 +191,10 @@ bool registerDocEvent( SfxObjectShell* pShell )
1003 for( const DocEventNameTable* pTable = aEventNameTable; pTable->sEventName != NULL; pTable++ )
1005 rtl::OUString sEvt = rtl::OUString::createFromAscii( pTable->sEventName );
1006 - rtl::OUString sMacroName = rtl::OUString::createFromAscii( pTable->sMacroName );
1007 + String sMacroName = String::CreateFromAscii( pTable->sMacroName ).Insert( '.', 0 ).Insert( sThisDocument, 0);
1008 // fail to search the macro if the module is not specified.
1009 - String sFullPath = ooo::vba::findVBAMacro( pShell, sModule, sMacroName );
1010 - if( sFullPath.Len() == 0 )
1011 + ooo::vba::VBAMacroResolvedInfo aMacroInfo = ooo::vba::resolveVBAMacro( pShell, sMacroName );
1012 + if( !aMacroInfo.IsResolved() )
1015 uno::Sequence< beans::PropertyValue > aEvents;
1016 @@ -203,7 +203,7 @@ bool registerDocEvent( SfxObjectShell* pShell )
1017 aOpenEvt[ 0 ].Name = sEvtType;
1018 aOpenEvt[ 0 ].Value = uno::makeAny(sScript);
1019 aOpenEvt[ 1 ].Name = sScript;
1020 - rtl::OUString sUrl = ooo::vba::makeMacroURL( sFullPath );
1021 + rtl::OUString sUrl = ooo::vba::makeMacroURL( aMacroInfo.ResolvedMacro() );
1022 aOpenEvt[ 1 ].Value = uno::makeAny(sUrl);
1023 sal_Int32 nPos = aEvents.getLength();
1025 @@ -3834,6 +3834,39 @@ void SwWW8ImplReader::ReadDocInfo()
1029 +void lcl_createTemplateToProjectEntry( const uno::Reference< container::XNameContainer >& xPrjNameCache, const rtl::OUString& sTemplatePathOrURL, const rtl::OUString& sVBAProjName )
1031 + if ( xPrjNameCache.is() )
1033 + INetURLObject aObj;
1034 + aObj.SetURL( sTemplatePathOrURL );
1035 + bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID;
1036 + rtl::OUString aURL;
1038 + aURL = sTemplatePathOrURL;
1041 + osl::FileBase::getFileURLFromSystemPath( sTemplatePathOrURL, aURL );
1042 + aObj.SetURL( aURL );
1046 + rtl::OUString templateNameWithExt = aObj.GetLastName();
1047 + rtl::OUString templateName;
1048 + sal_Int32 nIndex = templateNameWithExt.lastIndexOf( '.' );
1049 + //xPrjNameCache->insertByName( templateNameWithExt, uno::makeAny( sVBAProjName ) );
1050 + if ( nIndex != -1 )
1052 + templateName = templateNameWithExt.copy( 0, nIndex );
1053 + xPrjNameCache->insertByName( templateName, uno::makeAny( sVBAProjName ) );
1056 + catch( uno::Exception& )
1062 class WW8Customizations
1064 SvStream* mpTableStream;
1065 @@ -3863,7 +3896,7 @@ bool WW8Customizations::Import( SwDocShell* pShell )
1066 return aTCG.ImportCustomToolBar( *pShell );
1069 -bool SwWW8ImplReader::ReadGlobalTemplateSettings()
1070 +bool SwWW8ImplReader::ReadGlobalTemplateSettings( const rtl::OUString& sCreatedFrom, const uno::Reference< container::XNameContainer >& xPrjNameCache )
1072 SvtPathOptions aPathOpt;
1073 String aAddinPath = aPathOpt.GetAddinPath();
1074 @@ -3878,11 +3911,6 @@ bool SwWW8ImplReader::ReadGlobalTemplateSettings()
1075 sal_Int32 nEntries = sGlobalTemplates.getLength();
1077 const SvtFilterOptions* pVBAFlags = SvtFilterOptions::Get();
1078 - uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( mpDocShell->GetModel(), uno::UNO_QUERY_THROW );
1079 - uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW );
1080 - uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW );
1082 - rtl::OUString sCreatedFrom = xDocProps->getTemplateURL();
1083 for ( sal_Int32 i=0; i<nEntries; ++i )
1086 @@ -3897,13 +3925,17 @@ bool SwWW8ImplReader::ReadGlobalTemplateSettings()
1087 continue; // don't try and read the same document as ourselves
1089 SotStorageRef rRoot = new SotStorage( aURL, STREAM_STD_READWRITE, STORAGE_TRANSACTED );
1091 // Read Macro Projects
1092 SvxImportMSVBasic aVBasic(*mpDocShell, *rRoot,
1093 pVBAFlags->IsLoadWordBasicCode(),
1094 pVBAFlags->IsLoadWordBasicStorage() );
1097 String s1(CREATE_CONST_ASC("Macros"));
1098 String s2(CREATE_CONST_ASC("VBA"));
1099 int nRet = aVBasic.Import( s1, s2, ! pVBAFlags->IsLoadWordBasicCode() );
1100 + lcl_createTemplateToProjectEntry( xPrjNameCache, aURL, aVBasic.GetVBAProjectName() );
1101 // Read toolbars & menus
1102 SvStorageStreamRef refMainStream = rRoot->OpenSotStream( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WordDocument") ) );
1103 refMainStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
1104 @@ -4183,10 +4215,20 @@ ULONG SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos)
1105 // dissable below for 3.1 at the moment, 'cause it's kinda immature
1106 // similarly the project reference in svx/source/msvba
1108 + uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( mpDocShell->GetModel(), uno::UNO_QUERY_THROW );
1109 + uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW );
1110 + uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW );
1112 + rtl::OUString sCreatedFrom = xDocProps->getTemplateURL();
1113 + uno::Reference< container::XNameContainer > xPrjNameCache;
1114 + uno::Reference< lang::XMultiServiceFactory> xSF(mpDocShell->GetModel(), uno::UNO_QUERY);
1116 + xPrjNameCache.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAProjectNameProvider" ) ) ), uno::UNO_QUERY );
1118 // Read Global templates
1119 - ReadGlobalTemplateSettings();
1120 + ReadGlobalTemplateSettings( sCreatedFrom, xPrjNameCache );
1122 - // Create and insert Excel vba Globals
1123 + // Create and insert Word vba Globals
1125 aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString::createFromAscii( "ooo.vba.word.Globals") );
1126 mpDocShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", aGlobs );
1127 @@ -4200,6 +4242,7 @@ ULONG SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos)
1128 // dissable below for 3.1 at the moment, 'cause it's kinda immature
1129 // similarly the project reference in svx/source/msvba
1131 + lcl_createTemplateToProjectEntry( xPrjNameCache, sCreatedFrom, aVBasic.GetVBAProjectName() );
1132 WW8Customizations aCustomisations( pTableStream, *pWwFib );
1133 aCustomisations.Import( mpDocShell );
1135 diff --git sw/source/filter/ww8/ww8par.hxx sw/source/filter/ww8/ww8par.hxx
1136 index 89ab0d6..9389568 100644
1137 --- sw/source/filter/ww8/ww8par.hxx
1138 +++ sw/source/filter/ww8/ww8par.hxx
1139 @@ -1415,7 +1415,7 @@ private:
1140 // determine object attribute "Layout in Table Cell"
1141 bool IsObjectLayoutInTableCell( const UINT32 nLayoutInTableCell ) const;
1143 - bool ReadGlobalTemplateSettings();
1144 + bool ReadGlobalTemplateSettings( const rtl::OUString& sCreatedFrom, const com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >& xPrjNameMap );
1146 SwWW8ImplReader(const SwWW8ImplReader &);
1147 SwWW8ImplReader& operator=(const SwWW8ImplReader&);
1148 diff --git sw/source/ui/uno/unotxdoc.cxx sw/source/ui/uno/unotxdoc.cxx
1149 index 0aacbda..9bc3d85 100644
1150 --- sw/source/ui/uno/unotxdoc.cxx
1151 +++ sw/source/ui/uno/unotxdoc.cxx
1152 @@ -225,6 +225,12 @@ sal_Int64 SAL_CALL SwXTextDocument::getSomething( const Sequence< sal_Int8 >& rI
1154 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
1156 + if( rId.getLength() == 16
1157 + && 0 == rtl_compareMemory( SfxObjectShell::getUnoTunnelId().getConstArray(),
1158 + rId.getConstArray(), 16 ) )
1160 + return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pDocShell ));
1163 sal_Int64 nRet = SfxBaseModel::getSomething( rId );
1165 diff --git vbahelper/inc/vbahelper/vbahelper.hxx vbahelper/inc/vbahelper/vbahelper.hxx
1166 index 1849437..77eb2a3 100644
1167 --- vbahelper/inc/vbahelper/vbahelper.hxx
1168 +++ vbahelper/inc/vbahelper/vbahelper.hxx
1169 @@ -63,6 +63,7 @@ namespace ooo
1170 throw css::lang::IllegalArgumentException();
1173 + VBAHELPER_DLLPUBLIC SfxObjectShell* getSfxObjShell( const css::uno::Reference< css::frame::XModel >& xModel ) throw ( css::uno::RuntimeException);
1174 VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > createVBAUnoAPIService( SfxObjectShell* pShell, const sal_Char* _pAsciiName ) throw (css::uno::RuntimeException);
1175 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);
1176 VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentDocument() throw (css::uno::RuntimeException);
1177 diff --git vbahelper/source/vbahelper/vbaapplicationbase.cxx vbahelper/source/vbahelper/vbaapplicationbase.cxx
1178 index a424b35..0d9f52e 100644
1179 --- vbahelper/source/vbahelper/vbaapplicationbase.cxx
1180 +++ vbahelper/source/vbahelper/vbaapplicationbase.cxx
1181 @@ -134,234 +134,39 @@ VbaApplicationBase::getVersion() throw (uno::RuntimeException)
1183 void SAL_CALL VbaApplicationBase::Run( const ::rtl::OUString& MacroName, const uno::Any& varg1, const uno::Any& varg2, const uno::Any& varg3, const uno::Any& varg4, const uno::Any& varg5, const uno::Any& varg6, const uno::Any& varg7, const uno::Any& varg8, const uno::Any& varg9, const uno::Any& varg10, const uno::Any& varg11, const uno::Any& varg12, const uno::Any& varg13, const uno::Any& varg14, const uno::Any& varg15, const uno::Any& varg16, const uno::Any& varg17, const uno::Any& varg18, const uno::Any& varg19, const uno::Any& varg20, const uno::Any& varg21, const uno::Any& varg22, const uno::Any& varg23, const uno::Any& varg24, const uno::Any& varg25, const uno::Any& varg26, const uno::Any& varg27, const uno::Any& varg28, const uno::Any& varg29, const uno::Any& varg30 ) throw (uno::RuntimeException)
1185 - // parse the macro name
1186 - sal_Int32 nDocSepIndex = MacroName.indexOfAsciiL( "!", 1 );
1187 - String sMacroUrl = MacroName;
1188 - uno::Reference< frame::XModel > xModel;
1189 - if( nDocSepIndex > 0 )
1190 + VBAMacroResolvedInfo aMacroInfo = resolveVBAMacro( GetDocShell( getCurrentDocument() ), MacroName );
1191 + if( aMacroInfo.IsResolved() )
1193 - rtl::OUString sTemplate = MacroName.copy( 0, nDocSepIndex );
1194 - OSL_TRACE("VbaApplicationBase::Run, template name: %s", rtl::OUStringToOString( sTemplate, RTL_TEXTENCODING_UTF8 ).getStr() );
1195 - sMacroUrl = MacroName.copy( nDocSepIndex + 1 );
1196 - OSL_TRACE("VbaApplicationBase::Run, macro name: %s", rtl::OUStringToOString( sMacroUrl, RTL_TEXTENCODING_UTF8 ).getStr() );
1197 + // handle the arguments
1198 + const uno::Any* aArgsPtrArray[] = { &varg1, &varg2, &varg3, &varg4, &varg5, &varg6, &varg7, &varg8, &varg9, &varg10, &varg11, &varg12, &varg13, &varg14, &varg15, &varg16, &varg17, &varg18, &varg19, &varg20, &varg21, &varg22, &varg23, &varg24, &varg25, &varg26, &varg27, &varg28, &varg29, &varg30 };
1200 - // get the template model
1201 - uno::Reference< lang::XMultiComponentFactory > xSMgr( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
1202 + int nArg = sizeof( aArgsPtrArray ) / sizeof( aArgsPtrArray[0] );
1203 + uno::Sequence< uno::Any > aArgs( nArg );
1205 - uno::Reference< frame::XDesktop > xDesktop
1206 - (xSMgr->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"), mxContext), uno::UNO_QUERY_THROW );
1207 - uno::Reference< container::XEnumeration > mxComponents = xDesktop->getComponents()->createEnumeration();
1208 - sal_Int32 nCount = 0;
1209 - while( mxComponents->hasMoreElements() )
1211 - uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( mxComponents->nextElement(), uno::UNO_QUERY );
1212 - if( xDocInfoSupp.is() )
1214 - uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW );
1215 - uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW );
1216 - rtl::OUString sCurrName = xDocProps->getTemplateName();
1217 - OSL_TRACE("VbaApplicationBase::Run, current template %d name: %s", ++nCount, rtl::OUStringToOString( sCurrName, RTL_TEXTENCODING_UTF8 ).getStr() );
1218 - // FIXME: should be check the full path of the template
1219 - if( sTemplate.lastIndexOf( sCurrName ) >= 0 )
1221 - xModel.set( xDocInfoSupp, uno::UNO_QUERY_THROW );
1225 + const uno::Any** pArg = aArgsPtrArray;
1226 + const uno::Any** pArgEnd = ( aArgsPtrArray + nArg );
1228 + sal_Int32 nLastArgWithValue = 0;
1229 + sal_Int32 nArgProcessed = 0;
1231 + for ( ; pArg != pArgEnd; ++pArg, ++nArgProcessed )
1233 + aArgs[ nArgProcessed ] = **pArg;
1234 + if( (*pArg)->hasValue() )
1235 + nLastArgWithValue = nArgProcessed;
1240 - xModel = getCurrentDocument();
1243 - if( !xModel.is() )
1245 - throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Fail to find the template in Application.Run") ), uno::Reference< uno::XInterface >() );
1247 + // resize array to position of last param with value
1248 + aArgs.realloc( nArgProcessed + 1 );
1252 - sal_Int32 nTokens = sMacroUrl.GetTokenCount( '.' );
1253 - xub_StrLen nToken = 0;
1254 - xub_StrLen nIndex = 0;
1255 - // only support ThisModule.ThisMacro
1256 - if( nTokens == 2 )
1258 - sModule = sMacroUrl.GetToken( nToken, '.', nIndex );
1259 - sMacro = sMacroUrl.GetToken( nToken, '.', nIndex );
1261 + uno::Any aDummyCaller;
1262 + executeMacro( aMacroInfo.MacroDocContext(), aMacroInfo.ResolvedMacro(), aArgs, aRet, aDummyCaller );
1266 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("The macro doesn't exist") ), uno::Reference< uno::XInterface >() );
1269 - SfxObjectShell* pShell = GetDocShell( xModel );
1272 - sMacroUrl = findVBAMacro( pShell, sModule, sMacro );
1273 - if( sMacroUrl.Len() )
1275 - // handle the arguments
1276 - uno::Sequence< uno::Any > aArgs;
1277 - if( varg1.hasValue() )
1279 - aArgs.realloc( aArgs.getLength() + 1 );
1280 - aArgs[ aArgs.getLength() ] = varg1;
1282 - if( varg2.hasValue() )
1284 - aArgs.realloc( aArgs.getLength() + 1 );
1285 - aArgs[ aArgs.getLength() ] = varg2;
1287 - if( varg3.hasValue() )
1289 - aArgs.realloc( aArgs.getLength() + 1 );
1290 - aArgs[ aArgs.getLength() ] = varg3;
1292 - if( varg4.hasValue() )
1294 - aArgs.realloc( aArgs.getLength() + 1 );
1295 - aArgs[ aArgs.getLength() ] = varg4;
1297 - if( varg5.hasValue() )
1299 - aArgs.realloc( aArgs.getLength() + 1 );
1300 - aArgs[ aArgs.getLength() ] = varg5;
1302 - if( varg6.hasValue() )
1304 - aArgs.realloc( aArgs.getLength() + 1 );
1305 - aArgs[ aArgs.getLength() ] = varg6;
1307 - if( varg7.hasValue() )
1309 - aArgs.realloc( aArgs.getLength() + 1 );
1310 - aArgs[ aArgs.getLength() ] = varg7;
1312 - if( varg8.hasValue() )
1314 - aArgs.realloc( aArgs.getLength() + 1 );
1315 - aArgs[ aArgs.getLength() ] = varg8;
1317 - if( varg9.hasValue() )
1319 - aArgs.realloc( aArgs.getLength() + 1 );
1320 - aArgs[ aArgs.getLength() ] = varg9;
1322 - if( varg10.hasValue() )
1324 - aArgs.realloc( aArgs.getLength() + 1 );
1325 - aArgs[ aArgs.getLength() ] = varg10;
1327 - if( varg11.hasValue() )
1329 - aArgs.realloc( aArgs.getLength() + 1 );
1330 - aArgs[ aArgs.getLength() ] = varg11;
1332 - if( varg12.hasValue() )
1334 - aArgs.realloc( aArgs.getLength() + 1 );
1335 - aArgs[ aArgs.getLength() ] = varg12;
1337 - if( varg13.hasValue() )
1339 - aArgs.realloc( aArgs.getLength() + 1 );
1340 - aArgs[ aArgs.getLength() ] = varg13;
1342 - if( varg14.hasValue() )
1344 - aArgs.realloc( aArgs.getLength() + 1 );
1345 - aArgs[ aArgs.getLength() ] = varg14;
1347 - if( varg15.hasValue() )
1349 - aArgs.realloc( aArgs.getLength() + 1 );
1350 - aArgs[ aArgs.getLength() ] = varg15;
1352 - if( varg16.hasValue() )
1354 - aArgs.realloc( aArgs.getLength() + 1 );
1355 - aArgs[ aArgs.getLength() ] = varg16;
1357 - if( varg17.hasValue() )
1359 - aArgs.realloc( aArgs.getLength() + 1 );
1360 - aArgs[ aArgs.getLength() ] = varg17;
1362 - if( varg18.hasValue() )
1364 - aArgs.realloc( aArgs.getLength() + 1 );
1365 - aArgs[ aArgs.getLength() ] = varg18;
1367 - if( varg19.hasValue() )
1369 - aArgs.realloc( aArgs.getLength() + 1 );
1370 - aArgs[ aArgs.getLength() ] = varg19;
1372 - if( varg20.hasValue() )
1374 - aArgs.realloc( aArgs.getLength() + 1 );
1375 - aArgs[ aArgs.getLength() ] = varg20;
1377 - if( varg21.hasValue() )
1379 - aArgs.realloc( aArgs.getLength() + 1 );
1380 - aArgs[ aArgs.getLength() ] = varg21;
1382 - if( varg22.hasValue() )
1384 - aArgs.realloc( aArgs.getLength() + 1 );
1385 - aArgs[ aArgs.getLength() ] = varg22;
1387 - if( varg23.hasValue() )
1389 - aArgs.realloc( aArgs.getLength() + 1 );
1390 - aArgs[ aArgs.getLength() ] = varg23;
1392 - if( varg24.hasValue() )
1394 - aArgs.realloc( aArgs.getLength() + 1 );
1395 - aArgs[ aArgs.getLength() ] = varg24;
1397 - if( varg25.hasValue() )
1399 - aArgs.realloc( aArgs.getLength() + 1 );
1400 - aArgs[ aArgs.getLength() ] = varg25;
1402 - if( varg26.hasValue() )
1404 - aArgs.realloc( aArgs.getLength() + 1 );
1405 - aArgs[ aArgs.getLength() ] = varg26;
1407 - if( varg27.hasValue() )
1409 - aArgs.realloc( aArgs.getLength() + 1 );
1410 - aArgs[ aArgs.getLength() ] = varg27;
1412 - if( varg28.hasValue() )
1414 - aArgs.realloc( aArgs.getLength() + 1 );
1415 - aArgs[ aArgs.getLength() ] = varg28;
1417 - if( varg29.hasValue() )
1419 - aArgs.realloc( aArgs.getLength() + 1 );
1420 - aArgs[ aArgs.getLength() ] = varg29;
1422 - if( varg30.hasValue() )
1424 - aArgs.realloc( aArgs.getLength() + 1 );
1425 - aArgs[ aArgs.getLength() ] = varg30;
1428 - executeMacro( pShell, sMacroUrl, aArgs, aRet );
1432 - throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("The macro doesn't exist") ), uno::Reference< uno::XInterface >() );
1437 float SAL_CALL VbaApplicationBase::CentimetersToPoints( float _Centimeters ) throw (uno::RuntimeException)
1438 diff --git vbahelper/source/vbahelper/vbacommandbarcontrol.cxx vbahelper/source/vbahelper/vbacommandbarcontrol.cxx
1439 index 718cdd0..2fcce8a 100644
1440 --- vbahelper/source/vbahelper/vbacommandbarcontrol.cxx
1441 +++ vbahelper/source/vbahelper/vbacommandbarcontrol.cxx
1443 #include <basic/sbstar.hxx>
1444 #include <basic/sbmod.hxx>
1445 #include <basic/sbmeth.hxx>
1446 +#include <vbahelper/vbahelper.hxx>
1447 +#include <svx/msvbahelper.hxx>
1449 using namespace com::sun::star;
1450 using namespace ooo::vba;
1451 @@ -286,79 +288,31 @@ ScVbaCommandBarControl::setOnAction( const ::rtl::OUString& _onaction ) throw (u
1453 if( m_xCurrentSettings.is() )
1455 - // convert the comand url into something like vnd.sun.star.script:Standard.testMacro.Macro1?language=Basic&location=document
1456 - rtl::OUString aCommandURL;
1457 - rtl::OUString sScheme = rtl::OUString::createFromAscii( "vnd.sun.star.script:");
1458 - SbModule* pModule = StarBASIC::GetActiveModule();
1459 - StarBASIC* pLib = pModule ? dynamic_cast< StarBASIC* >( pModule->GetParent() ) : NULL;
1461 - // Ok, we should be able to deal with the following params for onAction
1462 - // a) macro ( we assume the macro lives in this Project ( that is not really a valid assumption but we can't currently search outside this Library yet )
1463 - // b) module.macro ( again assume the macro is in this Project )
1464 - // c) project.module.macro fully specified
1466 - if( pModule && pLib )
1467 + // get the current model
1468 + uno::Reference< frame::XModel > xModel( getCurrentDocument() );
1469 + VBAMacroResolvedInfo aResolvedMacro = ooo::vba::resolveVBAMacro( getSfxObjShell( xModel ), _onaction, true );
1470 + if ( aResolvedMacro.IsResolved() )
1474 - String sMacro = _onaction;
1476 - sal_Int32 nMacroDot = _onaction.lastIndexOf( '.' );
1478 - if ( nMacroDot != -1 )
1479 + rtl::OUString aCommandURL = ooo::vba::makeMacroURL( aResolvedMacro.ResolvedMacro() );
1480 + OSL_TRACE(" ScVbaCommandBarControl::setOnAction: %s", rtl::OUStringToOString( aCommandURL, RTL_TEXTENCODING_UTF8 ).getStr() );
1481 + beans::PropertyValues aPropertyValues;
1482 + m_xCurrentSettings->getByIndex( m_nPosition ) >>= aPropertyValues;
1483 + beans::PropertyValues aNewPropertyValues;
1484 + aNewPropertyValues = lcl_repalcePropertyValue( aPropertyValues, rtl::OUString::createFromAscii("CommandURL"), uno::makeAny( aCommandURL ) );
1485 + m_xCurrentSettings->replaceByIndex( m_nPosition, uno::makeAny( aNewPropertyValues ) );
1486 + if( m_xUICfgManager->hasSettings( m_sBarName ) )
1488 - sMacro = _onaction.copy( nMacroDot + 1 );
1490 - sal_Int32 nProjectDot = _onaction.lastIndexOf( '.', nMacroDot - 1 );
1491 - if ( nProjectDot != -1 )
1493 - sModule = _onaction.copy( nProjectDot + 1, nMacroDot - nProjectDot - 1 );
1494 - pModule = NULL; // force full spec. no search
1498 - sModule = _onaction.copy( 0, nMacroDot );
1499 - pModule = pLib->FindModule( sModule );
1500 + m_xUICfgManager->replaceSettings( m_sBarName, uno::Reference< container::XIndexAccess > (m_xBarSettings, uno::UNO_QUERY_THROW ) );
1503 - // Hopefully eventually if no project is specified 'Find' below
1504 - // will do the right thing
1505 - if( SbMethod* pMethod = dynamic_cast< SbMethod* >( pModule ? pModule->Find( sMacro, SbxCLASS_METHOD ) : NULL ) )
1510 - sModule = pModule->GetName();
1511 - sProject = pModule->GetParent()->GetName();
1513 + m_xUICfgManager->insertSettings( m_sBarName, uno::Reference< container::XIndexAccess > (m_xBarSettings, uno::UNO_QUERY_THROW ) );
1515 + // make it permanent
1516 + if( !m_bTemporary )
1518 + m_xUICfgPers->store();
1520 - sMacro.Insert( '.', 0 ).Insert( sModule, 0 ).Insert( '.', 0 ).Insert( sProject, 0 );
1522 - rtl::OUString sUrlPart2 = rtl::OUString::createFromAscii( "?language=Basic&location=document");
1523 - aCommandURL = sScheme.concat( sMacro ).concat( sUrlPart2 );
1524 - OSL_TRACE("**** METHOD IS %s", rtl::OUStringToOString( aCommandURL, RTL_TEXTENCODING_UTF8 ).getStr() );
1528 - aCommandURL = _onaction;
1530 - OSL_TRACE(" ScVbaCommandBarControl::setOnAction: %s", rtl::OUStringToOString( aCommandURL, RTL_TEXTENCODING_UTF8 ).getStr() );
1531 - beans::PropertyValues aPropertyValues;
1532 - m_xCurrentSettings->getByIndex( m_nPosition ) >>= aPropertyValues;
1533 - beans::PropertyValues aNewPropertyValues;
1534 - aNewPropertyValues = lcl_repalcePropertyValue( aPropertyValues, rtl::OUString::createFromAscii("CommandURL"), uno::makeAny( aCommandURL ) );
1535 - m_xCurrentSettings->replaceByIndex( m_nPosition, uno::makeAny( aNewPropertyValues ) );
1536 - if( m_xUICfgManager->hasSettings( m_sBarName ) )
1538 - m_xUICfgManager->replaceSettings( m_sBarName, uno::Reference< container::XIndexAccess > (m_xBarSettings, uno::UNO_QUERY_THROW ) );
1542 - m_xUICfgManager->insertSettings( m_sBarName, uno::Reference< container::XIndexAccess > (m_xBarSettings, uno::UNO_QUERY_THROW ) );
1544 - // make it permanent
1545 - if( !m_bTemporary )
1547 - m_xUICfgPers->store();
1551 diff --git vbahelper/source/vbahelper/vbahelper.cxx vbahelper/source/vbahelper/vbahelper.cxx
1552 index 57bca7c..97ebb3b 100644
1553 --- vbahelper/source/vbahelper/vbahelper.cxx
1554 +++ vbahelper/source/vbahelper/vbahelper.cxx
1556 #include <toolkit/awt/vclxwindow.hxx>
1557 #include <toolkit/helper/vclunohelper.hxx>
1558 #include <com/sun/star/frame/XModel2.hpp>
1559 +#include <com/sun/star/lang/XUnoTunnel.hpp>
1560 #include <vcl/window.hxx>
1561 #include <vcl/syswin.hxx>
1562 #include <tools/diagnose_ex.h>
1563 @@ -1116,7 +1117,19 @@ UserFormGeometryHelper::UserFormGeometryHelper( const uno::Reference< uno::XComp
1564 double points = double( static_cast<double>(_hmm) / factor);
1569 + SfxObjectShell* getSfxObjShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
1571 + SfxObjectShell* pFoundShell = NULL;
1572 + if ( xModel.is() )
1574 + uno::Reference< lang::XUnoTunnel > xObjShellTunnel( xModel, uno::UNO_QUERY_THROW );
1575 + pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId()));
1577 + if ( !pFoundShell )
1578 + throw uno::RuntimeException();
1579 + return pFoundShell;