1. mst
  2. ooo340

Commits

npower Developer  committed a77fbc6

support import of project name

  • Participants
  • Parent commits 5140738
  • Branches default

Comments (0)

Files changed (13)

File basic/source/classes/sbxmod.cxx

View file
             aArgs[ 0 ] <<= m_xModel;
             rtl::OUString sDialogUrl( RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.script:" ) );
             rtl::OUString sProjectName( RTL_CONSTASCII_USTRINGPARAM("Standard") );
-            if ( this->GetParent()->GetName().Len() )
-                sProjectName = this->GetParent()->GetName(); 
+
+            try
+            {
+                Reference< beans::XPropertySet > xProps( m_xModel, UNO_QUERY_THROW );
+                uno::Reference< script::XVBACompat > xVBAMode( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BasicLibraries") ) ), uno::UNO_QUERY_THROW );
+                sProjectName = xVBAMode->getProjectName();
+            }
+            catch( Exception& /*e*/) {}
+
             sDialogUrl = sDialogUrl.concat( sProjectName ).concat( rtl::OUString( '.') ).concat( GetName() ).concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("?location=document") ) ); 
 
             uno::Reference< awt::XDialogProvider > xProvider( xFactory->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.DialogProvider")), aArgs  ), uno::UNO_QUERY_THROW );

File basic/source/inc/namecont.hxx

View file
                             ,public ::utl::OEventListenerAdapter
 {
     sal_Bool mbVBACompat;
+    rtl::OUString msProjectName;
 protected:
     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >   mxMSF;
 	::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >       mxSFI;
 	// Methods XVBACompat
 	virtual ::sal_Bool SAL_CALL getVBACompatModeOn() throw (::com::sun::star::uno::RuntimeException);
 	virtual void SAL_CALL setVBACompatModeOn( ::sal_Bool _vbacompatmodeon ) throw (::com::sun::star::uno::RuntimeException);
+        virtual ::rtl::OUString SAL_CALL getProjectName() throw (::com::sun::star::uno::RuntimeException) { return msProjectName; }
+        virtual void SAL_CALL setProjectName( const ::rtl::OUString& _projectname ) throw (::com::sun::star::uno::RuntimeException);
+        
 };
 
 class LibraryContainerMethodGuard

File basic/source/uno/namecont.cxx

View file
         mbVBACompat = _vbacompatmodeon;
 }
 
+void SAL_CALL SfxLibraryContainer::setProjectName( const ::rtl::OUString& _projectname ) throw (RuntimeException) 
+{ 
+	msProjectName = _projectname;
+	BasicManager* pBasMgr = getBasicManager();
+	// Temporary HACK
+	// Some parts of the VBA handling ( e.g. in core basic )
+	// code expect the name of the VBA project to be set as the name of 
+	// the basic manager. Provide fail back here.
+	if( pBasMgr )
+		pBasMgr->SetName( msProjectName );	
+}
+
 // Methods XServiceInfo
 ::sal_Bool SAL_CALL SfxLibraryContainer::supportsService( const ::rtl::OUString& _rServiceName )
     throw (RuntimeException)

File filter/source/msfilter/msvbahelper.cxx

View file
 #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/XVBACompat.hpp>
 #include <tools/urlobj.hxx>
 #include <osl/file.hxx>
 
         {
             // 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 )
+            rtl::OUString sThisProject = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") );
+            try
             {
-                if ( pBasicMgr->GetName().Len() )
-                   sThisProject = pBasicMgr->GetName();
-                else // cater for the case where VBA is not enabled
-                   sThisProject = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") );
+                uno::Reference< beans::XPropertySet > xProps( pShell->GetModel(), uno::UNO_QUERY_THROW );
+                uno::Reference< script::XVBACompat > xVBAMode( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BasicLibraries") ) ), uno::UNO_QUERY_THROW );
+                sThisProject = xVBAMode->getProjectName();
             }
+            catch( uno::Exception& /*e*/) {}
+
             sSearchList.push_back( sThisProject ); // First Lib to search
             if ( xPrjNameCache.is() )
             {

File offapi/com/sun/star/script/XVBACompat.idl

View file
 
 //============================================================================= 
     [attribute ] boolean VBACompatModeOn;
+    [attribute ] string  ProjectName;
  
 }; }; }; };  
 }; 

File oox/inc/oox/ole/vbahelper.hxx

View file
 const sal_uInt16 VBA_ID_MODULETYPEDOCUMENT      = 0x0022;
 const sal_uInt16 VBA_ID_MODULETYPEPROCEDURAL    = 0x0021;
 const sal_uInt16 VBA_ID_PROJECTCODEPAGE         = 0x0003;
+const sal_uInt16 VBA_ID_PROJECTNAME             = 0x0004;
 const sal_uInt16 VBA_ID_PROJECTEND              = 0x0010;
 const sal_uInt16 VBA_ID_PROJECTMODULES          = 0x000F;
 const sal_uInt16 VBA_ID_PROJECTVERSION          = 0x0009;

File oox/inc/oox/ole/vbaproject.hxx

View file
                         mxBasicLib;         /// The Basic library of the document used for import.
     ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
                         mxDialogLib;        /// The dialog library of the document used for import.
-    const ::rtl::OUString maLibName;        /// Name for Basic and dialog library used for import.
+    ::rtl::OUString     maPrjName;        /// Name of VBA project being imported
 };
 
 // ============================================================================

File oox/source/ole/vbaproject.cxx

View file
     VbaFilterConfig( rxGlobalFactory, rConfigCompName ),
     mxGlobalFactory( rxGlobalFactory ),
     mxDocModel( rxDocModel ),
-    maLibName( CREATE_OUSTRING( "Standard" ) )
+    maPrjName( CREATE_OUSTRING( "Standard" ) )
 {
     OSL_ENSURE( mxDocModel.is(), "VbaProject::VbaProject - missing document model" );
-    mxBasicLib = openLibrary( PROP_BasicLibraries, false );
-    mxDialogLib = openLibrary( PROP_DialogLibraries, false );
 }
 
 VbaProject::~VbaProject()
         // check that the specified macro exists in the module
         VbaHelper::hasMacro( mxBasicLib, rModuleName, rMacroName ) &&
         // attach the macro to the events supplier
-        VbaHelper::attachMacroToEvent( rxEventsSupp, rEventName, maLibName, rModuleName, rMacroName );
+        VbaHelper::attachMacroToEvent( rxEventsSupp, rEventName, maPrjName, rModuleName, rMacroName );
 }
 
 bool VbaProject::attachMacroToDocumentEvent( const OUString& rEventName,
         // insert the new macro into the code module and attach it to the event
         return
             VbaHelper::insertMacro( mxBasicLib, rModuleName, aProxyName, rProxyArgs, rProxyType, aProxyCode ) &&
-            VbaHelper::attachMacroToEvent( rxEventsSupp, rEventName, maLibName, rModuleName, aProxyName );
+            VbaHelper::attachMacroToEvent( rxEventsSupp, rEventName, maPrjName, rModuleName, aProxyName );
     }
     return false;
 }
     try
     {
         Reference< XLibraryContainer > xLibContainer( getLibraryContainer( nPropId ), UNO_SET_THROW );
-        if( bCreateMissing && !xLibContainer->hasByName( maLibName ) )
-            xLibContainer->createLibrary( maLibName );
-        xLibrary.set( xLibContainer->getByName( maLibName ), UNO_QUERY_THROW );
+        if( bCreateMissing && !xLibContainer->hasByName( maPrjName ) )
+            xLibContainer->createLibrary( maPrjName );
+        xLibrary.set( xLibContainer->getByName( maPrjName ), UNO_QUERY_THROW );
     }
     catch( Exception& )
     {
                 aModulesByStrm[ rxModule->getStreamName() ] = rxModule;
             }
             break;
+            case VBA_ID_PROJECTNAME:
+            {
+                maPrjName = aRecStrm.readCharArrayUC( nRecSize, eTextEnc );
+                OSL_ENSURE( maPrjName.getLength() > 0, "VbaProject::importVba - invalid project name" );
+            }
+            break;
 #undef OOX_ENSURE_RECORDSIZE
         }
     }
     }
 
     /*  Now it is time to load the source code. All modules will be inserted
-        into the Basic library of the document specified by the 'maLibName'
+        into the Basic library of the document specified by the 'maPrjName'
         member. Do not create the Basic library, if there are no modules
         specified. */
     if( !aModules.empty() ) try
         // set library container to VBA compatibility mode
         try
         {
-            Reference< XVBACompat >( getLibraryContainer( PROP_BasicLibraries ), UNO_QUERY_THROW )->setVBACompatModeOn( sal_True );
+            Reference< XVBACompat > xVBACompat( getLibraryContainer( PROP_BasicLibraries ), UNO_QUERY_THROW );
+            xVBACompat->setVBACompatModeOn( sal_True );
+            xVBACompat->setProjectName( maPrjName );
         }
         catch( Exception& )
         {

File sc/source/ui/docshell/docsh5.cxx

View file
 #include <svl/smplhint.hxx>
 
 #include <com/sun/star/sdbc/XResultSet.hpp>
+#include <com/sun/star/script/XVBACompat.hpp>
 
 // INCLUDE ---------------------------------------------------------------
 
 // defined in docfunc.cxx
 void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, String& sModuleName, String& sModuleSource );
 
+using com::sun::star::script::XLibraryContainer;
+using com::sun::star::script::XVBACompat;
+using com::sun::star::container::XNameContainer;
+using com::sun::star::uno::Reference;
+using com::sun::star::uno::UNO_QUERY;
+
 // ---------------------------------------------------------------------------
 
 //
                         {
 			    StarBASIC* pStarBASIC = GetBasic();
                             String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
-                            if ( GetBasicManager()->GetName().Len() > 0 )
+                            Reference< XLibraryContainer > xLibContainer = GetBasicContainer();
+                            Reference< XVBACompat > xVBACompat( xLibContainer, UNO_QUERY );
+
+                            if ( xVBACompat.is() )
                             {
-                                aLibName = GetBasicManager()->GetName();
+                                aLibName = xVBACompat->getProjectName();
                                 pStarBASIC = GetBasicManager()->GetLib( aLibName );
                             }
+
                             SCTAB nTabToUse = nDestTab; 
                             if ( nDestTab == SC_TAB_APPEND )
                                 nTabToUse = aDocument.GetMaxTableNumber() - 1;
                             String sCodeName;
                             String sSource;
-                            com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibContainer = GetBasicContainer();
-                            com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xLib;
+                            Reference< XNameContainer > xLib;
                             if( xLibContainer.is() )
                             {
                                 com::sun::star::uno::Any aLibAny = xLibContainer->getByName( aLibName );
 	{
 		ScRange aRange;
 		pDBData->GetArea( aRange );
-        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> xResultSet;
+                Reference< ::com::sun::star::sdbc::XResultSet> xResultSet;
 		bContinue = aFunc.DoImport( aRange.aStart.Tab(), aImportParam, xResultSet, NULL, TRUE, FALSE );	//! Api-Flag as parameter
 		// internal operations (sort, query, subtotal) only if no error
 		if (bContinue)

File scripting/prj/build.lst

View file
-tc	scripting	:	oovbaapi vbahelper bridges rdbmaker vcl xmlscript basic sfx2 rhino BSH:beanshell javaunohelper NULL
+tc	scripting	:	filter oovbaapi vbahelper bridges rdbmaker vcl xmlscript basic sfx2 rhino BSH:beanshell javaunohelper NULL
 tc	scripting									usr1	-	all	tc1_mkout NULL
 tc	scripting\inc								nmake	-	all	tc1_inc NULL
 tc	scripting\source\provider				nmake	-	all	tc1_scriptingprovider tc1_inc NULL

File scripting/source/vbaevents/eventhelper.cxx

View file
 #include <com/sun/star/script/XLibraryContainer.hpp>
 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
+#include <com/sun/star/script/XVBACompat.hpp>
 
 #include <com/sun/star/drawing/XControlShape.hpp>
 
 #include <basic/sbmeth.hxx>
 #include <basic/sbmod.hxx>
 #include <basic/sbx.hxx>
-
+#include <filter/msfilter/msvbahelper.hxx>
 
 
 
     Reference< XComponentContext > m_xContext;
     Reference< frame::XModel > m_xModel;
     SfxObjectShell* mpShell;
-    
+    rtl::OUString msProject; 
 };
 
 EventListener::EventListener( const Reference< XComponentContext >& rxContext ) :
 {
     registerProperty( EVENTLSTNR_PROPERTY_MODEL, EVENTLSTNR_PROPERTY_ID_MODEL,
         beans::PropertyAttribute::TRANSIENT, &m_xModel, ::getCppuType( &m_xModel ) );
-
+    msProject = rtl::OUString::createFromAscii("Standard");
 }
 
 void
 		}
 		pShell = SfxObjectShell::GetNext( *pShell );
 	}    
+	// set ProjectName from model
+	try
+	{
+		Reference< beans::XPropertySet > xProps( m_xModel, UNO_QUERY_THROW );
+		uno::Reference< script::XVBACompat > xVBAMode( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BasicLibraries") ) ), uno::UNO_QUERY_THROW );
+		msProject = xVBAMode->getProjectName();
+	}
+	catch ( uno::Exception& ) {}    
 }
 
 //XEventListener
 // EventListener
 
 void
-EventListener::firing_Impl(const ScriptEvent& evt, Any* /*pRet*/ ) throw(RuntimeException)
+EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) throw(RuntimeException)
 {
 	OSL_TRACE("EventListener::firing_Impl( FAKE VBA_EVENTS )");
     static const ::rtl::OUString vbaInterOp =
         std::list< TranslateInfo >::const_iterator txInfo =
             eventInfo_it->second.begin();
         std::list< TranslateInfo >::const_iterator txInfo_end = eventInfo_it->second.end();
-        rtl::OUString sMacroLoc = rtl::OUString::createFromAscii("Standard.").concat( evt.ScriptCode ).concat( rtl::OUString::createFromAscii(".") );
        
         StarBASIC* pBasic = mpShell->GetBasic();
-        SbModule* pModule = pBasic->FindModule( evt.ScriptCode );
-        for ( ; pModule && txInfo != txInfo_end; ++txInfo )
+        BasicManager* pBasicManager = mpShell->GetBasicManager();
+        rtl::OUString sProject( msProject );
+        rtl::OUString sScriptCode( evt.ScriptCode );
+	// dialogs pass their own library, presence of Dot determines that
+	if ( sScriptCode.indexOf( '.' ) != -1 )
+	{
+		sal_Int32 nIndex = sScriptCode.indexOf( '.' );
+		sProject = sScriptCode.copy( 0, nIndex );
+                sScriptCode = sScriptCode.copy( nIndex + 1 );
+	}
+        rtl::OUString sMacroLoc = sProject;
+        sMacroLoc = sMacroLoc.concat(  rtl::OUString::createFromAscii(".") );
+        sMacroLoc = sMacroLoc.concat( sScriptCode ).concat( rtl::OUString::createFromAscii(".") );
+        
+        OSL_TRACE("sMacroLoc is %s", rtl::OUStringToOString( sMacroLoc, RTL_TEXTENCODING_UTF8 ).getStr() );
+        for ( ; txInfo != txInfo_end; ++txInfo )
         {
+            rtl::OUString sTemp = sName.concat( (*txInfo).sVBAName ); 
             // see if we have a match for the handlerextension
             // where ScriptCode is methodname_handlerextension 
-            rtl::OUString sTemp = sName.concat( (*txInfo).sVBAName ); 
-            
+            rtl::OUString sToResolve = sMacroLoc.concat( sTemp );
+
             OSL_TRACE("*** trying to invoke %s ",
-                rtl::OUStringToOString( sTemp, RTL_TEXTENCODING_UTF8 ).getStr() );
-            SbMethod* pMeth = static_cast< SbMethod* >( pModule->Find( sTemp, SbxCLASS_METHOD ) );
-            if ( pMeth )
+                rtl::OUStringToOString( sToResolve, RTL_TEXTENCODING_UTF8 ).getStr() );
+            ooo::vba::VBAMacroResolvedInfo aMacroResolvedInfo = ooo::vba::resolveVBAMacro( mpShell, sToResolve ); 
+            if ( aMacroResolvedInfo.IsResolved() )
             {
 				//liuchen 2009-6-8
 				if (! txInfo->ApproveRule(evt, txInfo->pPara) )
                 {
                     // call basic event handlers for event
 
-                    static rtl::OUString part1 = rtl::OUString::createFromAscii( "vnd.sun.star.script:");
-                    static rtl::OUString part2 = rtl::OUString::createFromAscii("?language=Basic&location=document"); 
-
                     // create script url
-                    rtl::OUString url = part1 + sMacroLoc + sTemp + part2;
-                 
-                    OSL_TRACE("script url = %s",
+                    rtl::OUString url = aMacroResolvedInfo.ResolvedMacro();
+                    OSL_TRACE("resolved script = %s",
                         rtl::OUStringToOString( url, 
                             RTL_TEXTENCODING_UTF8 ).getStr() );
-                    Sequence< sal_Int16 > aOutArgsIndex;
-                    Sequence< Any > aOutArgs;
                     try
                     {
-                        if ( mpShell )
+                        uno::Any aDummyCaller = uno::makeAny( rtl::OUString::createFromAscii("Error") );
+                        if ( pRet )
+                            ooo::vba::executeMacro( mpShell, url, aArguments, *pRet, aDummyCaller ); 
+                        else
                         {
                             uno::Any aRet;
-                            mpShell->CallXScript( url,
-                                aArguments, aRet, aOutArgsIndex, aOutArgs, false );
+                            ooo::vba::executeMacro( mpShell, url, aArguments, aRet, aDummyCaller ); 
                         }
                     }
                     catch ( uno::Exception& e )

File scripting/source/vbaevents/makefile.mk

View file
 		$(BASICLIB) \
 		$(COMPHELPERLIB) \
 		$(SFXLIB) \
+                $(MSFILTERLIB) \
                 $(CPPULIB) \
                 $(TOOLSLIB) \
                 $(SALLIB)

File toolkit/source/controls/dialogcontrol.cxx

View file
-/*************************************************************************
+ /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *