[ooo-build-commit] .: 2 commits - patches/dev300 patches/vba

Noel Power noelp at kemper.freedesktop.org
Thu Jul 8 14:37:03 PDT 2010


 patches/dev300/apply                     |   16 -
 patches/vba/vba-oox-autocodename.diff    |  262 +++++++++++++++++
 patches/vba/vba-oox-olenameoverride.diff |  464 +++++++++++++++++++++++++++++++
 3 files changed, 732 insertions(+), 10 deletions(-)

New commits:
commit e3be25bba395f8259687575dd4a642c91a501230
Author: Noel Power <noel.power at novell.com>
Date:   Thu Jul 8 22:00:36 2010 +0100

    rewrite ( deleted ) olenameoverride patch
    
    * patches/vba/vba-oox-olenameoverride.diff:

diff --git a/patches/vba/vba-oox-olenameoverride.diff b/patches/vba/vba-oox-olenameoverride.diff
index e69de29..a222863 100644
--- a/patches/vba/vba-oox-olenameoverride.diff
+++ b/patches/vba/vba-oox-olenameoverride.diff
@@ -0,0 +1,464 @@
+diff --git oox/inc/oox/helper/containerhelper.hxx oox/inc/oox/helper/containerhelper.hxx
+index 25065f9..89445c4 100644
+--- oox/inc/oox/helper/containerhelper.hxx
++++ oox/inc/oox/helper/containerhelper.hxx
+@@ -124,6 +124,13 @@ public:
+                             forEach( ::boost::bind( pFunc, _1, aParam1, aParam2, aParam3 ) );
+                         }
+ 
++    /** Calls the passed member function of ObjType on every contained object,
++        automatically skips all elements that are empty references. */
++    template< typename FuncType, typename ParamType1, typename ParamType2, typename ParamType3, typename ParamType4 >
++    inline void         forEachMem( FuncType pFunc, ParamType1 aParam1, ParamType2 aParam2, ParamType3 aParam3, ParamType4 aParam4 ) const
++                        {
++                            forEach( ::boost::bind( pFunc, _1, aParam1, aParam2, aParam3, aParam4 ) );
++                        }
+     /** Calls the passed functor for every contained object. Passes the index as
+         first argument and the object reference as second argument to rFunctor. */
+     template< typename FunctorType >
+@@ -281,6 +288,13 @@ public:
+                         {
+                             forEach( ::boost::bind( pFunc, _1, aParam1, aParam2, aParam3 ) );
+                         }
++    /** Calls the passed member function of ObjType on every contained object,
++        automatically skips all elements that are empty references. */
++    template< typename FuncType, typename ParamType1, typename ParamType2, typename ParamType3, typename ParamType4 >
++    inline void         forEachMem( FuncType pFunc, ParamType1 aParam1, ParamType2 aParam2, ParamType3 aParam3, ParamType4 aParam4 ) const
++                        {
++                            forEach( ::boost::bind( pFunc, _1, aParam1, aParam2, aParam3, aParam4 ) );
++                        }
+     /** Calls the passed functor for every contained object. Passes the key as
+         first argument and the object reference as second argument to rFunctor. */
+     template< typename FunctorType >
+diff --git oox/inc/oox/ole/vbamodule.hxx oox/inc/oox/ole/vbamodule.hxx
+index cef676d..c93a54f 100755
+--- oox/inc/oox/ole/vbamodule.hxx
++++ oox/inc/oox/ole/vbamodule.hxx
+@@ -30,6 +30,7 @@
+ 
+ #include <rtl/ustring.hxx>
+ #include <com/sun/star/uno/Reference.hxx>
++#include <tools/string.hxx>
+ 
+ namespace com { namespace sun { namespace star {
+     namespace container { class XNameAccess; }
+@@ -72,13 +73,15 @@ public:
+     void                importSourceCode(
+                             StorageBase& rVbaStrg,
+                             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxBasicLib,
+-                            const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& rxDocObjectNA ) const;
++                            const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& rxDocObjectNA, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxOleNameOverrides ) const;
+ 
+     /** Creates empty document module for the passed Basic library/project. */
+     void                createEmptyDocModule(
+                             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxBasicLib,
+                             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& rxDocObjectNA ) const;
+ private:
++    void extractOleOverrideFromAttr( const String& rAttribute, 
++                                     const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxOleNameOverrides ) const;
+     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
+                         mxDocModel;         /// Document model used to import/export the VBA project.
+     ::rtl::OUString     maName;
+diff --git oox/inc/oox/ole/vbaproject.hxx oox/inc/oox/ole/vbaproject.hxx
+index 6198ae7..d4665b6 100755
+--- oox/inc/oox/ole/vbaproject.hxx
++++ oox/inc/oox/ole/vbaproject.hxx
+@@ -248,7 +248,7 @@ public:
+                             const ::rtl::OUString& rProxyArgs,
+                             const ::rtl::OUString& rProxyType,
+                             const ::rtl::OUString& rProxyCode );
+-
++    void                setOleOverridesSink( ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >&  rxOleOverridesSink ){ mxOleOverridesSink = rxOleOverridesSink; }
+ private:
+                         VbaProject( const VbaProject& );
+     VbaProject&         operator=( const VbaProject& );
+@@ -279,6 +279,8 @@ private:
+                         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.
++    ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
++                        mxOleOverridesSink;
+     ::rtl::OUString     maPrjName;        /// Name of VBA project being imported
+ };
+ 
+diff --git oox/source/ole/vbamodule.cxx oox/source/ole/vbamodule.cxx
+index 156dc12..2ce7c3e 100755
+--- oox/source/ole/vbamodule.cxx
++++ oox/source/ole/vbamodule.cxx
+@@ -27,6 +27,7 @@
+ 
+ #include "oox/ole/vbamodule.hxx"
+ #include <com/sun/star/container/XNameContainer.hpp>
++#include <com/sun/star/container/XIndexContainer.hpp>
+ #include <com/sun/star/script/ModuleInfo.hpp>
+ #include <com/sun/star/script/ModuleType.hpp>
+ #include <com/sun/star/script/XVBAModuleInfo.hpp>
+@@ -35,17 +36,28 @@
+ #include "oox/helper/textinputstream.hxx"
+ #include "oox/ole/vbahelper.hxx"
+ #include "oox/ole/vbainputstream.hxx"
++#include <hash_map>
++#include <cppuhelper/implbase1.hxx>
+ 
+ using ::rtl::OUString;
+ using ::rtl::OUStringBuffer;
+ using ::com::sun::star::container::XNameAccess;
+ using ::com::sun::star::container::XNameContainer;
++using ::com::sun::star::container::XIndexContainer;
++using ::com::sun::star::container::ElementExistException;
++using ::com::sun::star::container::NoSuchElementException;
++using ::com::sun::star::lang::IndexOutOfBoundsException;
++using ::com::sun::star::lang::WrappedTargetException;
++using ::com::sun::star::lang::IllegalArgumentException;
+ using ::com::sun::star::frame::XModel;
+ using ::com::sun::star::script::ModuleInfo;
+ using ::com::sun::star::script::XVBAModuleInfo;
+ using ::com::sun::star::uno::Any;
++using ::com::sun::star::uno::Type;
++using ::com::sun::star::uno::makeAny;
+ using ::com::sun::star::uno::Exception;
+ using ::com::sun::star::uno::Reference;
++using ::com::sun::star::uno::RuntimeException;
+ using ::com::sun::star::uno::UNO_QUERY;
+ using ::com::sun::star::uno::UNO_QUERY_THROW;
+ 
+@@ -55,6 +67,70 @@ namespace oox {
+ namespace ole {
+ 
+ // ============================================================================
++typedef ::cppu::WeakImplHelper1< XIndexContainer > OleIdToNameContainer_BASE;
++typedef std::hash_map< sal_Int32, rtl::OUString >  ObjIdToName;
++class OleIdToNameContainer : public OleIdToNameContainer_BASE
++{
++    ObjIdToName ObjIdToNameHash;
++    ::osl::Mutex m_aMutex;
++    bool hasByIndex( ::sal_Int32 Index )
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        return ( ObjIdToNameHash.find( Index ) != ObjIdToNameHash.end() );
++    }
++public:
++    OleIdToNameContainer() {}
++    // XIndexContainer Methods
++    virtual void SAL_CALL insertByIndex( ::sal_Int32 Index, const Any& Element ) throw (IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        rtl::OUString sOleName;
++        if ( !( Element >>= sOleName ) )
++            throw IllegalArgumentException();
++        ObjIdToNameHash[ Index ] = sOleName;
++    }
++    virtual void SAL_CALL removeByIndex( ::sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        if ( !hasByIndex( Index ) )
++            throw IndexOutOfBoundsException();
++        ObjIdToNameHash.erase( ObjIdToNameHash.find( Index ) );
++    }
++    // XIndexReplace Methods
++    virtual void SAL_CALL replaceByIndex( ::sal_Int32 Index, const Any& Element ) throw (IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        if ( !hasByIndex( Index ) )
++            throw IndexOutOfBoundsException();
++        rtl::OUString sOleName;
++        if ( !( Element >>= sOleName ) )
++            throw IllegalArgumentException();
++        ObjIdToNameHash[ Index ] = sOleName;
++    }
++    // XIndexAccess Methods
++    virtual ::sal_Int32 SAL_CALL getCount(  ) throw (RuntimeException)
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        return ObjIdToNameHash.size();
++    }
++    virtual Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        if ( !hasByIndex( Index ) )
++            throw IndexOutOfBoundsException();
++        return makeAny( ObjIdToNameHash[ Index ] );
++    }
++    // XElementAccess Methods
++    virtual Type SAL_CALL getElementType(  ) throw (RuntimeException)
++    {
++        return ::getCppuType((const ::rtl::OUString*)(NULL) );
++    }
++    virtual ::sal_Bool SAL_CALL hasElements(  ) throw (RuntimeException)
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        return ( getCount() > 0 );
++    }
++};
+ 
+ VbaModule::VbaModule( const Reference< XModel >& rxDocModel, const OUString& rName, rtl_TextEncoding eTextEnc, bool bExecutable ) :
+     mxDocModel( rxDocModel ),
+@@ -134,8 +210,35 @@ void VbaModule::importDirRecords( BinaryInputStream& rDirStrm )
+     OSL_ENSURE( mnOffset < SAL_MAX_UINT32, "VbaModule::importDirRecords - missing module stream offset" );
+ }
+ 
++void VbaModule::extractOleOverrideFromAttr( const String& rAttributeLine,
++                                            const Reference< XNameContainer >& rxOleNameOverrides ) const
++{
++    String rAttribute = rAttributeLine;
++    // format of the attribute we are interested in is
++    // Attribute VB_Control = "ControlName", intString, MSForms, ControlTypeAsString
++    // e.g.
++    // Attribute VB_Control = "CommandButton1, 201, 19, MSForms, CommandButton"
++    String sControlAttribute( RTL_CONSTASCII_USTRINGPARAM("Attribute VB_Control = \"") );
++    if ( rxOleNameOverrides.is() && rAttribute.Search( sControlAttribute ) !=  STRING_NOTFOUND )
++    {
++        String sRest = rAttribute.Copy( sControlAttribute.Len() );
++        xub_StrLen nPos = 0; 
++        String sCntrlName = sRest.GetToken( 0, ',', nPos );
++        
++        sal_Int32 nCntrlId = sRest.GetToken( 0, ',', nPos).ToInt32();
++        OSL_TRACE("In module %s, assiging %d controlname %s", 
++            rtl::OUStringToOString( maName, RTL_TEXTENCODING_UTF8 ).getStr(), nCntrlId,
++            rtl::OUStringToOString( sCntrlName, RTL_TEXTENCODING_UTF8 ).getStr() );
++        if ( !rxOleNameOverrides->hasByName( maName ) )
++            rxOleNameOverrides->insertByName( maName, makeAny( Reference< XIndexContainer> ( new OleIdToNameContainer() ) ) );
++        Reference< XIndexContainer > xIdToOleName;
++        if ( rxOleNameOverrides->getByName( maName ) >>= xIdToOleName )
++            xIdToOleName->insertByIndex( nCntrlId, makeAny( rtl::OUString( sCntrlName ) ) );
++    }
++}
++
+ void VbaModule::importSourceCode( StorageBase& rVbaStrg,
+-        const Reference< XNameContainer >& rxBasicLib, const Reference< XNameAccess >& rxDocObjectNA ) const
++        const Reference< XNameContainer >& rxBasicLib, const Reference< XNameAccess >& rxDocObjectNA,  const Reference< XNameContainer >& rxOleNameOverrides ) const
+ {
+     if( (maName.getLength() == 0) || (maStreamName.getLength() == 0) || (mnOffset == SAL_MAX_UINT32) )
+         return;
+@@ -208,6 +311,8 @@ void VbaModule::importSourceCode( StorageBase& rVbaStrg,
+                 aSourceCode.appendAscii( RTL_CONSTASCII_STRINGPARAM( "Rem " ) );
+             aSourceCode.append( aCodeLine ).append( sal_Unicode( '\n' ) );
+         }
++        else
++            extractOleOverrideFromAttr( aCodeLine, rxOleNameOverrides );
+     }
+ 
+     // close the subroutine named after the module
+diff --git oox/source/ole/vbaproject.cxx oox/source/ole/vbaproject.cxx
+index 22a7019..cf419ce 100755
+--- oox/source/ole/vbaproject.cxx
++++ oox/source/ole/vbaproject.cxx
+@@ -473,7 +473,7 @@ void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGrap
+             aGeneratedModules.forEachMem( &VbaModule::createEmptyDocModule,
+                 ::boost::cref( xBasicLib ), ::boost::cref( xDocObjectNA ) );
+             aModules.forEachMem( &VbaModule::importSourceCode,
+-                ::boost::ref( *xVbaStrg ), ::boost::cref( xBasicLib ), ::boost::cref( xDocObjectNA ) );
++                ::boost::ref( *xVbaStrg ), ::boost::cref( xBasicLib ), ::boost::cref( xDocObjectNA ), ::boost::cref( mxOleOverridesSink ) );
+         }
+     }
+     catch( Exception& )
+diff --git oox/source/xls/excelfilter.cxx oox/source/xls/excelfilter.cxx
+index 5ae1148..fed9dcd 100644
+--- oox/source/xls/excelfilter.cxx
++++ oox/source/xls/excelfilter.cxx
+@@ -35,6 +35,7 @@
+ #include "oox/xls/workbookfragment.hxx"
+ #include "oox/dump/biffdumper.hxx"
+ #include "oox/dump/xlsbdumper.hxx"
++#include <com/sun/star/container/XNameContainer.hpp>
+ 
+ using ::rtl::OUString;
+ using ::com::sun::star::uno::Any;
+@@ -42,6 +43,7 @@ using ::com::sun::star::uno::Reference;
+ using ::com::sun::star::uno::Sequence;
+ using ::com::sun::star::uno::Exception;
+ using ::com::sun::star::uno::XInterface;
++using ::com::sun::star::container::XNameContainer;
+ using ::com::sun::star::lang::XMultiServiceFactory;
+ using ::com::sun::star::xml::sax::XFastDocumentHandler;
+ using ::oox::core::BinaryFilterBase;
+@@ -278,11 +280,14 @@ bool SimpleExcelVBAProjFilter::importDocument() throw()
+     {
+         Sequence< rtl::OUString > sGeneratedCNames;
+         getArgument( CREATE_OUSTRING( "GeneratedCodeNames" ) ) >>= sGeneratedCNames;
++        Reference< XNameContainer > xOleNameOverrideSink;
++        getArgument( CREATE_OUSTRING( "OleNameOverrideInfo" ) ) >>= xOleNameOverrideSink;
+         WorkbookHelperRoot aHelper( *this, eBiff );
+         StorageRef xVbaPrjStrg = openSubStorage( CREATE_OUSTRING( "_VBA_PROJECT_CUR" ), false )    ;
+         if( xVbaPrjStrg.get() && xVbaPrjStrg->isStorage() )
+         {
+             VbaProject aVbaProject( getGlobalFactory(), aHelper.getDocument() );
++            aVbaProject.setOleOverridesSink( xOleNameOverrideSink );
+             aVbaProject.importVbaProject( *xVbaPrjStrg, getGraphicHelper(), sGeneratedCNames );
+             bRet = true;
+         }
+diff --git sc/source/filter/excel/excimp8.cxx sc/source/filter/excel/excimp8.cxx
+index 4909aaf..0010cee 100644
+--- sc/source/filter/excel/excimp8.cxx
++++ sc/source/filter/excel/excimp8.cxx
+@@ -116,6 +116,85 @@ using namespace ::comphelper;
+ 
+ #define	INVALID_POS		0xFFFFFFFF
+ 
++//OleNameOverrideContainer
++
++typedef ::cppu::WeakImplHelper1< container::XNameContainer > OleNameOverrideContainer_BASE;
++
++class OleNameOverrideContainer : public OleNameOverrideContainer_BASE
++{
++private:
++    typedef std::hash_map< rtl::OUString, uno::Reference< container::XIndexContainer >, ::rtl::OUStringHash,
++       ::std::equal_to< ::rtl::OUString > > NamedIndexToOleName;
++    NamedIndexToOleName  IdToOleNameHash;
++    ::osl::Mutex m_aMutex;
++public:
++    // XElementAccess
++    virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException) { return  container::XIndexContainer::static_type(0); }
++    virtual ::sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException) 
++    { 
++        ::osl::MutexGuard aGuard( m_aMutex );
++        return ( IdToOleNameHash.size() > 0 ); 
++    }
++    // XNameAcess 
++    virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        if ( !hasByName(aName) )
++            throw container::NoSuchElementException();
++        return uno::makeAny( IdToOleNameHash[ aName ] );
++    }
++    virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw (uno::RuntimeException)
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        uno::Sequence< ::rtl::OUString > aResult( IdToOleNameHash.size() );
++        NamedIndexToOleName::iterator it = IdToOleNameHash.begin();
++        NamedIndexToOleName::iterator it_end = IdToOleNameHash.end();
++        rtl::OUString* pName = aResult.getArray();
++        for (; it != it_end; ++it, ++pName )
++            *pName = it->first; 
++        return aResult;
++    }
++    virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        return ( IdToOleNameHash.find( aName ) != IdToOleNameHash.end() );        
++    }
++
++    // XElementAccess
++    virtual ::sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException) 
++    { 
++        ::osl::MutexGuard aGuard( m_aMutex );
++        return IdToOleNameHash.size(); 
++    }	
++    // XNameContainer
++    virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const uno::Any& aElement ) throw(lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException)
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        if ( hasByName( aName ) )
++            throw container::ElementExistException();
++        uno::Reference< container::XIndexContainer > xElement;
++        if ( ! ( aElement >>= xElement ) )
++            throw lang::IllegalArgumentException(); 
++       IdToOleNameHash[ aName ] = xElement;
++    }
++    virtual void SAL_CALL removeByName( const ::rtl::OUString& aName ) throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        if ( !hasByName( aName ) )
++            throw container::NoSuchElementException(); 
++        IdToOleNameHash.erase( IdToOleNameHash.find( aName ) );
++    }
++    virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement ) throw(lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
++    {
++        ::osl::MutexGuard aGuard( m_aMutex );
++        if ( !hasByName( aName ) )
++            throw container::NoSuchElementException(); 
++        uno::Reference< container::XIndexContainer > xElement;
++        if ( ! ( aElement >>= xElement ) )
++            throw lang::IllegalArgumentException(); 
++        IdToOleNameHash[ aName ] = xElement;
++    }    
++};
+ 
+ // defined in docfunc.cxx ( really this needs a new name )
+ script::ModuleInfo lcl_InitModuleInfo( SfxObjectShell& rDocSh, String& sModule );
+@@ -291,7 +370,7 @@ void ImportExcel8::ReadBasic( void )
+             try
+             {
+                 uno::Reference< lang::XComponent > xComponent( pShell->GetModel(), uno::UNO_QUERY_THROW );
+-                uno::Sequence< beans::NamedValue > aArgSeq(1);
++                uno::Sequence< beans::NamedValue > aArgSeq(2);
+                 // I guess we could actually handle the GeneratedCodeNames here
+                 // ( e.g. after import create the required modules ) but...
+                 // better to reuse the code in the filter right?
+@@ -307,6 +386,10 @@ void ImportExcel8::ReadBasic( void )
+                 }
+                 aArgSeq[ 0 ].Value <<= sGeneratedCNames;
+ 
++                aArgSeq[ 1 ].Name = CREATE_OUSTRING( "OleNameOverrideInfo");
++                uno::Reference< container::XNameContainer > xOleNameOverrideSink( new OleNameOverrideContainer() );
++                aArgSeq[ 1 ].Value <<=  xOleNameOverrideSink;
++       
+                 uno::Sequence< uno::Any > aArgs( 2 );
+                 aArgs[ 0 ] <<= getProcessServiceFactory();
+                 aArgs[ 1 ] <<= aArgSeq;
+@@ -331,6 +414,7 @@ void ImportExcel8::ReadBasic( void )
+                 // call the filter
+                 uno::Reference< document::XFilter > xFilter( xImporter, uno::UNO_QUERY_THROW );
+                 xFilter->filter( aMediaDesc.getAsConstPropertyValueList() );
++                GetObjectManager().SetOleNameOverrideInfo( xOleNameOverrideSink );
+             }
+             catch( uno::Exception& )
+             {
+@@ -355,11 +439,6 @@ void ImportExcel8::ReadBasic( void )
+ #endif
+ 
+             }
+-            // #FIXME how to get this info from oox
+-            #if FIXME
+-            if ( !bAsComment )
+-                GetObjectManager().SetOleNameOverrideInfo( aBasicImport.ControlNameForObjectId() );
+-            #endif
+         }
+     }
+ }
+diff --git sc/source/filter/excel/xiescher.cxx sc/source/filter/excel/xiescher.cxx
+index 6edcf86..afea800 100644
+--- sc/source/filter/excel/xiescher.cxx
++++ sc/source/filter/excel/xiescher.cxx
+@@ -3199,17 +3199,14 @@ XclImpDffConverter::~XclImpDffConverter()
+ 
+ String XclImpObjectManager::GetOleNameOverride( SCTAB nTab, sal_uInt16 nObjId )
+ {
+-    String sOleName; 
++    rtl::OUString sOleName; 
+     String sCodeName = GetExtDocOptions().GetCodeName( nTab );
+     
+-    CodeNameToCntrlObjIdInfo::iterator it = maOleCtrlNameOverride.find( sCodeName );
+-    if ( it != maOleCtrlNameOverride.end() )
++    if (  mxOleCtrlNameOverride->hasByName( sCodeName ) )
+     {
+-        CntrlObjIdToName::iterator it_id = it->second.find( nObjId );
+-        if ( it_id != it->second.end() )
+-        {
+-            sOleName = it_id->second;
+-        }
++        Reference< XIndexContainer > xIdToOleName;
++        mxOleCtrlNameOverride->getByName( sCodeName ) >>= xIdToOleName;
++        xIdToOleName->getByIndex( nObjId ) >>= sOleName;
+     }
+     OSL_TRACE("XclImpObjectManager::GetOleNameOverride tab %d, ( module %s ) object id ( %d ) is %s", nTab,
+         rtl::OUStringToOString( sCodeName, RTL_TEXTENCODING_UTF8 ).getStr(), nObjId,
+diff --git sc/source/filter/inc/xiescher.hxx sc/source/filter/inc/xiescher.hxx
+index a5998ed..38464fa 100644
+--- sc/source/filter/inc/xiescher.hxx
++++ sc/source/filter/inc/xiescher.hxx
+@@ -1232,11 +1232,12 @@ public:
+     String              GetDefaultObjName( const XclImpDrawObjBase& rDrawObj ) const;
+     /** Returns the used area in the sheet with the passed index. */
+     ScRange             GetUsedArea( SCTAB nScTab ) const;
+-    void SetOleNameOverrideInfo( const CodeNameToCntrlObjIdInfo& rOverrideInfo ) {  maOleCtrlNameOverride = rOverrideInfo; }
++    void SetOleNameOverrideInfo( const com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >& rxOverrideInfo ) {  mxOleCtrlNameOverride = rxOverrideInfo; }
+     String GetOleNameOverride( SCTAB nTab, sal_uInt16 nObjId );
+     // ------------------------------------------------------------------------
+ private:
+ 
++    com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >  mxOleCtrlNameOverride;
+     CodeNameToCntrlObjIdInfo maOleCtrlNameOverride;
+ 
+     /** Reads and returns a bitmap from WMF/PICT format. */
commit 529e56e5a3d996891a14d37ce9a06af430a3e046
Author: Noel Power <noel.power at novell.com>
Date:   Thu Jul 8 18:10:32 2010 +0100

    autocodename hack for n#507768
    
    * patches/dev300/apply:
    * patches/vba/vba-oox-autocodename.diff:
    * patches/vba/vba-oox-olenameoverride.diff: unfortunately blank as I overwrote this patch with the one above ( and hadn't commited ) starting again

diff --git a/patches/dev300/apply b/patches/dev300/apply
index 07919ca..6f79cd6 100644
--- a/patches/dev300/apply
+++ b/patches/dev300/apply
@@ -1587,16 +1587,12 @@ vba-enable-fieldrelatedbits.diff
 vba-container-controls.diff
 # need to adapt ooo-build wrt the changes intorduced into container_controls
 oox-projectname-oobuild-specifix.diff
-# container controls
-# Note: the fixme's below should be already integrated into the 
-# next generated diff for the cws ( e.g. container_controls )
-# FIXME dev300-m77 vba-container-controls.diff #disabled
-# fire change event when active tab is changed via api for multipage
-# FIXME dev300-m77 vba-multipage-fireapichange.diff #disabled
-# fix weird wizard truncation
-# FIXME dev300-m77 fix-containercontrols-wizardresize.diff, n#591768 #disabled
-
-
+# tweak oox filter to handle any passed generated code names 
+# there is a strange scenario with one cust doc where a code module is missing
+vba-oox-autocodename.diff
+# tweak oox filter to handle strange scenario where there might be some
+# missing codenmames in excel
+#vba-oox-olenameoverride.diff
 # fix strange ranges seperator regression problem
 fix-name-range-separator.diff, n#597351
 
diff --git a/patches/vba/vba-oox-autocodename.diff b/patches/vba/vba-oox-autocodename.diff
new file mode 100644
index 0000000..c99bb6a
--- /dev/null
+++ b/patches/vba/vba-oox-autocodename.diff
@@ -0,0 +1,262 @@
+diff --git oox/inc/oox/ole/vbamodule.hxx oox/inc/oox/ole/vbamodule.hxx
+index 3b529ce..cef676d 100755
+--- oox/inc/oox/ole/vbamodule.hxx
++++ oox/inc/oox/ole/vbamodule.hxx
+@@ -74,6 +74,10 @@ public:
+                             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxBasicLib,
+                             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& rxDocObjectNA ) const;
+ 
++    /** Creates empty document module for the passed Basic library/project. */
++    void                createEmptyDocModule(
++                            const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxBasicLib,
++                            const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& rxDocObjectNA ) const;
+ private:
+     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
+                         mxDocModel;         /// Document model used to import/export the VBA project.
+diff --git oox/inc/oox/ole/vbaproject.hxx oox/inc/oox/ole/vbaproject.hxx
+index 6087942..6198ae7 100755
+--- oox/inc/oox/ole/vbaproject.hxx
++++ oox/inc/oox/ole/vbaproject.hxx
+@@ -85,6 +85,7 @@ public:
+     void                importVbaProject(
+                             StorageBase& rVbaPrjStrg,
+                             const GraphicHelper& rGraphicHelper,
++                            const ::com::sun::star::uno::Sequence< rtl::OUString >& sGeneratedCNames = ::com::sun::star::uno::Sequence< rtl::OUString >(0),
+                             bool bDefaultColorBgr = true );
+ 
+     /** Returns true, if the document contains at least one code module. */
+@@ -265,7 +266,7 @@ private:
+     ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
+                         createDialogLibrary();
+     /** Imports the VBA code modules and forms. */
+-    void                importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper, bool bDefaultColorBgr );
++    void                importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper, const ::com::sun::star::uno::Sequence< rtl::OUString >& sGeneratedCNames, bool bDefaultColorBgr );
+     /** Copies the entire VBA project storage to the passed document model. */
+     void                copyStorage( StorageBase& rVbaPrjStrg );
+ 
+diff --git oox/source/ole/vbamodule.cxx oox/source/ole/vbamodule.cxx
+index 851bacc..156dc12 100755
+--- oox/source/ole/vbamodule.cxx
++++ oox/source/ole/vbamodule.cxx
+@@ -234,6 +234,46 @@ void VbaModule::importSourceCode( StorageBase& rVbaStrg,
+         OSL_ENSURE( false, "VbaModule::importSourceCode - cannot insert module into library" );
+     }
+ }
++void VbaModule::createEmptyDocModule( const Reference< XNameContainer >& rxBasicLib, const Reference< XNameAccess >& rxDocObjectNA ) const
++{
++    if( maName.getLength() == 0 ) 
++        return;
++        
++    // prepare the Basic module
++    ModuleInfo aModuleInfo;
++    aModuleInfo.ModuleType = mnType;
++    OUStringBuffer aSourceCode;
++    aSourceCode.appendAscii( RTL_CONSTASCII_STRINGPARAM( "Rem Attribute VBA_ModuleType=VBADocumentModule" ) );
++
++    // get the VBA object associated to the document module
++    if( rxDocObjectNA.is() ) try
++    {
++        aModuleInfo.ModuleObject.set( rxDocObjectNA->getByName( maName ), UNO_QUERY );
++    }
++    catch( Exception& )
++    {
++    }
++
++    // insert extended module info
++    try
++    {
++        Reference< XVBAModuleInfo > xVBAModuleInfo( rxBasicLib, UNO_QUERY_THROW );
++        xVBAModuleInfo->insertModuleInfo( maName, aModuleInfo );
++    }
++    catch( Exception& )
++    {
++    }
++
++    // insert the module into the passed Basic library
++    try
++    {
++        rxBasicLib->insertByName( maName, Any( aSourceCode.makeStringAndClear() ) );
++    }
++    catch( Exception& )
++    {
++        OSL_ENSURE( false, "VbaModule::importSourceCode - cannot insert module into library" );
++    }
++}
+ 
+ // ============================================================================
+ 
+diff --git oox/source/ole/vbaproject.cxx oox/source/ole/vbaproject.cxx
+index 10a7dc6..22a7019 100755
+--- oox/source/ole/vbaproject.cxx
++++ oox/source/ole/vbaproject.cxx
+@@ -65,6 +65,7 @@ using ::com::sun::star::script::XLibraryContainer;
+ using ::com::sun::star::script::XVBACompat;
+ using ::com::sun::star::uno::Any;
+ using ::com::sun::star::uno::Exception;
++using ::com::sun::star::uno::Sequence;
+ using ::com::sun::star::uno::Reference;
+ using ::com::sun::star::uno::UNO_QUERY;
+ using ::com::sun::star::uno::UNO_QUERY_THROW;
+@@ -149,13 +150,13 @@ VbaProject::~VbaProject()
+ {
+ }
+ 
+-void VbaProject::importVbaProject( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper, bool bDefaultColorBgr )
++void VbaProject::importVbaProject( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper, const Sequence< OUString >& rGeneratedCNames, bool bDefaultColorBgr )
+ {
+     if( rVbaPrjStrg.isStorage() )
+     {
+         // load the code modules and forms
+         if( isImportVba() )
+-            importVba( rVbaPrjStrg, rGraphicHelper, bDefaultColorBgr );
++            importVba( rVbaPrjStrg, rGraphicHelper, rGeneratedCNames, bDefaultColorBgr );
+         // copy entire storage into model
+         if( isExportVba() )
+             copyStorage( rVbaPrjStrg );
+@@ -286,7 +287,7 @@ Reference< XNameContainer > VbaProject::createDialogLibrary()
+     return mxDialogLib;
+ }
+ 
+-void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper, bool bDefaultColorBgr )
++void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper, const Sequence< OUString >& rGeneratedCNames, bool bDefaultColorBgr )
+ {
+     StorageRef xVbaStrg = rVbaPrjStrg.openSubStorage( CREATE_OUSTRING( "VBA" ), false );
+     OSL_ENSURE( xVbaStrg.get(), "VbaProject::importVba - cannot open 'VBA' substorage" );
+@@ -310,7 +311,7 @@ void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGrap
+     bool bExecutable = isImportVbaExecutable();
+ 
+     typedef RefMap< OUString, VbaModule > VbaModuleMap;
+-    VbaModuleMap aModules, aModulesByStrm;
++    VbaModuleMap aModules, aModulesByStrm, aGeneratedModules;
+ 
+     sal_uInt16 nRecId = 0;
+     StreamDataSequence aRecData;
+@@ -424,11 +425,21 @@ void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGrap
+         }
+     }
+ 
++    // populate aModules with modules from generated codenames ( if they exist )
++    const rtl::OUString* pGenModName = rGeneratedCNames.getConstArray();
++    const rtl::OUString* pEnd = rGeneratedCNames.getConstArray() + rGeneratedCNames.getLength();
++    for ( ; pGenModName != pEnd; ++pGenModName )
++    {
++        VbaModuleMap::mapped_type& rxModule = aGeneratedModules[ *pGenModName ];
++        rxModule.reset( new VbaModule( mxDocModel, *pGenModName, eTextEnc, bExecutable ) );
++        rxModule->setType( ApiModuleType::DOCUMENT );
++    }
++    
+     /*  Now it is time to load the source code. All modules will be inserted
+         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
++    if( !aModules.empty() || !aGeneratedModules.empty() ) try
+     {
+         // get the basic library
+         Reference< XNameContainer > xBasicLib( createBasicLibrary(), UNO_SET_THROW );
+@@ -458,8 +469,12 @@ void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGrap
+ 
+         // call Basic source code import for each module, boost::[c]ref enforces pass-by-ref
+         if( xBasicLib.is() )
++        {
++            aGeneratedModules.forEachMem( &VbaModule::createEmptyDocModule,
++                ::boost::cref( xBasicLib ), ::boost::cref( xDocObjectNA ) );
+             aModules.forEachMem( &VbaModule::importSourceCode,
+                 ::boost::ref( *xVbaStrg ), ::boost::cref( xBasicLib ), ::boost::cref( xDocObjectNA ) );
++        }
+     }
+     catch( Exception& )
+     {
+diff --git oox/source/xls/excelfilter.cxx oox/source/xls/excelfilter.cxx
+index ffed051..5ae1148 100644
+--- oox/source/xls/excelfilter.cxx
++++ oox/source/xls/excelfilter.cxx
+@@ -276,12 +276,14 @@ bool SimpleExcelVBAProjFilter::importDocument() throw()
+     OSL_ENSURE( eBiff != BIFF_UNKNOWN, "ExcelBiffFilter::ExcelBiffFilter - invalid file format" );
+     if( eBiff != BIFF_UNKNOWN )
+     {
++        Sequence< rtl::OUString > sGeneratedCNames;
++        getArgument( CREATE_OUSTRING( "GeneratedCodeNames" ) ) >>= sGeneratedCNames;
+         WorkbookHelperRoot aHelper( *this, eBiff );
+         StorageRef xVbaPrjStrg = openSubStorage( CREATE_OUSTRING( "_VBA_PROJECT_CUR" ), false )    ;
+         if( xVbaPrjStrg.get() && xVbaPrjStrg->isStorage() )
+         {
+             VbaProject aVbaProject( getGlobalFactory(), aHelper.getDocument() );
+-            aVbaProject.importVbaProject( *xVbaPrjStrg, getGraphicHelper() );
++            aVbaProject.importVbaProject( *xVbaPrjStrg, getGraphicHelper(), sGeneratedCNames );
+             bRet = true;
+         }
+     }
+diff --git sc/source/filter/excel/excimp8.cxx sc/source/filter/excel/excimp8.cxx
+index 7e1a181..29d6e69 100644
+--- sc/source/filter/excel/excimp8.cxx
++++ sc/source/filter/excel/excimp8.cxx
+@@ -121,7 +121,7 @@ using namespace ::comphelper;
+ script::ModuleInfo lcl_InitModuleInfo( SfxObjectShell& rDocSh, String& sModule );
+ 
+ ImportExcel8::ImportExcel8( XclImpRootData& rImpData, SvStream& rStrm ) :
+-    ImportExcel( rImpData, rStrm ), mnTab(0)
++    ImportExcel( rImpData, rStrm )
+ {
+     delete pFormConv;
+ 
+@@ -251,7 +251,7 @@ void ImportExcel8::Codename( BOOL bWorkbookGlobals )
+             else
+             {
+                 GetExtDocOptions().AppendCodeName( aName );
+-                GetDoc().SetCodeName( mnTab++, aName );
++                GetDoc().SetCodeName( GetCurrScTab(), aName );
+             }
+         }
+     }
+@@ -291,8 +291,28 @@ void ImportExcel8::ReadBasic( void )
+             try
+             {
+                 uno::Reference< lang::XComponent > xComponent( pShell->GetModel(), uno::UNO_QUERY_THROW );
+-                
+-                uno::Reference< document::XImporter > xImporter( ScfApiHelper::CreateInstance( CREATE_OUSTRING( "com.sun.star.comp.xls.SimpleExcelVBAProjFilter" ) ), uno::UNO_QUERY_THROW );
++                uno::Sequence< beans::NamedValue > aArgSeq(1);
++                // I guess we could actually handle the GeneratedCodeNames here
++                // ( e.g. after import create the required modules ) but...
++                // better to reuse the code in the filter right?
++                uno::Sequence< rtl::OUString > sGeneratedCNames;
++                aArgSeq[ 0 ].Name = CREATE_OUSTRING( "GeneratedCodeNames");
++                if (  AutoGeneratedCodeNames.size() )
++                {
++                    sGeneratedCNames.realloc( AutoGeneratedCodeNames.size() );
++                    std::vector< String >::iterator it_end = AutoGeneratedCodeNames.end();
++                    rtl::OUString* pItem = sGeneratedCNames.getArray();
++                    for ( std::vector< String >::iterator it = AutoGeneratedCodeNames.begin(); it != it_end; ++it, ++pItem )
++                        *pItem = *it;
++                }
++                aArgSeq[ 0 ].Value <<= sGeneratedCNames;
++
++                uno::Sequence< uno::Any > aArgs( 2 );
++                aArgs[ 0 ] <<= getProcessServiceFactory();
++                aArgs[ 1 ] <<= aArgSeq;
++
++                uno::Reference< document::XImporter > xImporter( ScfApiHelper::CreateInstanceWithArgs( CREATE_OUSTRING( "com.sun.star.comp.xls.SimpleExcelVBAProjFilter" ), aArgs ), uno::UNO_QUERY_THROW );
++
+                 xImporter->setTargetDocument( xComponent );
+     
+                 MediaDescriptor aMediaDesc;
+@@ -318,7 +338,6 @@ void ImportExcel8::ReadBasic( void )
+ 
+             if ( !bAsComment )
+             {
+-                ScDocument& rDoc = GetDoc();
+ #if 1
+                 // see if we have the XCB stream
+                 SvStorageStreamRef xXCB = xRootStrg->OpenSotStream( String( RTL_CONSTASCII_USTRINGPARAM( "XCB" ) ), STREAM_STD_READ | STREAM_NOCREATE  );
+diff --git sc/source/filter/inc/excimp8.hxx sc/source/filter/inc/excimp8.hxx
+index 4447768..0f84fd3 100644
+--- sc/source/filter/inc/excimp8.hxx
++++ sc/source/filter/inc/excimp8.hxx
+@@ -50,7 +50,6 @@ class XclImpStream;
+ 
+ class ImportExcel8 : public ImportExcel
+ {
+-        SCTAB mnTab;
+     protected:
+         // represents codename ( and associated modules ) 
+         // not speficied directly in the binary format
diff --git a/patches/vba/vba-oox-olenameoverride.diff b/patches/vba/vba-oox-olenameoverride.diff
new file mode 100644
index 0000000..e69de29


More information about the ooo-build-commit mailing list