Anonymous avatar Anonymous committed 215f2ce

mib20: do not look in class/document/form modules, when searching for a macro globally

Comments (0)

Files changed (2)

filter/inc/filter/msfilter/msvbahelper.hxx

 
     MSFILTER_DLLPUBLIC String makeMacroURL( const String& sMacroName );
     MSFILTER_DLLPUBLIC ::rtl::OUString extractMacroName( const ::rtl::OUString& rMacroUrl );
+    MSFILTER_DLLPUBLIC ::rtl::OUString getDefaultProjectName( SfxObjectShell* pShell );
     MSFILTER_DLLPUBLIC VBAMacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& sMod, bool bSearchGlobalTemplates = false );
     MSFILTER_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 );
 } }

filter/source/msfilter/msvbahelper.cxx

 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 #include <com/sun/star/document/XDocumentProperties.hpp>
 #include <com/sun/star/document/XDocumentInfoSupplier.hpp>
+#include <com/sun/star/script/ModuleType.hpp>
 #include <tools/urlobj.hxx>
 #include <osl/file.hxx>
 #include <unotools/pathoptions.hxx>
 
 // sMod can be empty ( but we really need the library to search in )
 // if sMod is empty and a macro is found then sMod is updated
+// if sMod is empty, only standard modules will be searched (no class, document, form modules)
 bool hasMacro( SfxObjectShell* pShell, const String& sLibrary, String& sMod, const String& sMacro )
 {
     bool bFound = false;
                 {
                     if( SbModule* pModule = pMethod->GetModule() )
                     {
-                        sMod = pModule->GetName();
-                        bFound = true;
+                        // when searching for a macro without module name, do not search in class/document/form modules
+                        if( pModule->GetModuleType() == script::ModuleType::NORMAL )
+                        {
+                            sMod = pModule->GetName();
+                            bFound = true;
+                        }
                     }
                 }
             }
     }
     return bFound;
 }
+
+::rtl::OUString getDefaultProjectName( SfxObjectShell* pShell )
+{
+    ::rtl::OUString aPrjName;
+    if( BasicManager* pBasicMgr = pShell ? pShell->GetBasicManager() : 0 )
+    {
+        aPrjName = pBasicMgr->GetName();
+        if( aPrjName.getLength() == 0 )
+            aPrjName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
+    }
+    return aPrjName;
+}
+
 void parseMacro( const rtl::OUString& sMacro, String& sContainer, String& sModule, String& sProcedure )
 {
     sal_Int32 nMacroDot = sMacro.lastIndexOf( '.' );
     
         // macro format = Container.Module.Procedure
         parseMacro( sMacroUrl, sContainer, sModule, sProcedure );
-        uno::Reference< container::XNameContainer > xPrjNameCache;
 
+#if 0
         // As long as service VBAProjectNameProvider isn't supported in the model, disable the createInstance call
         // (the ServiceNotRegisteredException is wrongly caught in ScModelObj::createInstance)
-        //uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY);
-        //if ( xSF.is() )
-        //    xPrjNameCache.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAProjectNameProvider" ) ) ), uno::UNO_QUERY );
+        uno::Reference< container::XNameContainer > xPrjNameCache;
+        uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY);
+        if ( xSF.is() ) try
+        {
+            xPrjNameCache.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAProjectNameProvider" ) ) ), uno::UNO_QUERY );
+        }
+        catch( uno::Exception& )    // createInstance may throw
+        {
+        }
+#endif
     
         std::vector< rtl::OUString > sSearchList; 
 
         if ( sContainer.Len() > 0 )
         { 
+// service VBAProjectNameProvider not implemented
+#if 0
             // get the Project associated with the Container
             if ( xPrjNameCache.is() )
             {
                     sContainer = sProject;
                 }
             }
+#endif
             sSearchList.push_back( sContainer ); // First Lib to search
         }
         else
         {
             // Ok, if we have no Container specified then we need to search them in order, this document, template this document created from, global templates, 
             // get the name of Project/Library for 'this' document
-            rtl::OUString sThisProject;
-            BasicManager* pBasicMgr = pShell-> GetBasicManager();
-            if ( pBasicMgr )
-            {
-                if ( pBasicMgr->GetName().Len() )
-                   sThisProject = pBasicMgr->GetName();
-                else // cater for the case where VBA is not enabled
-                   sThisProject = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") );
-            }
+            rtl::OUString sThisProject = getDefaultProjectName( pShell );
             sSearchList.push_back( sThisProject ); // First Lib to search
+
+// service VBAProjectNameProvider not implemented
+#if 0
             if ( xPrjNameCache.is() )
             {
                 // is this document created from a template?
         
                 }
             }
+#endif
         }
+
         std::vector< rtl::OUString >::iterator it_end = sSearchList.end();
         for ( std::vector< rtl::OUString >::iterator it = sSearchList.begin(); it != it_end; ++it )
         {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.