update ooo310-m15
[ooovba.git] / applied_patches / 0367-ObjectModule.diff
blob4cb9e9564a956871f6415ce68bd0cbe8615ce070
1 --- basctl/source/basicide/basides1.cxx.old 2009-04-02 10:56:36.000000000 +0000
2 +++ basctl/source/basicide/basides1.cxx 2009-04-06 16:41:59.000000000 +0000
3 @@ -1201,10 +1201,16 @@ IDEBaseWindow* BasicIDEShell::FindWindow
4 // return any non-suspended window
5 return pWin;
7 - else if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName && pWin->GetName() == rName &&
8 + else if ( pWin->IsDocument( rDocument ) )
9 + {
10 + OSL_TRACE("FindWindow pWin->GetLibName() %s rLibName %s",
11 + rtl::OUStringToOString( pWin->GetLibName(), RTL_TEXTENCODING_UTF8 ).getStr(),
12 + rtl::OUStringToOString( rLibName, RTL_TEXTENCODING_UTF8 ).getStr() );
13 + OSL_TRACE("pWin->pWin->IsA( TYPE( ModulWindow ) %d && nType %d = BASICIDE_TYPE_MODULE %d", pWin->IsA( TYPE( ModulWindow ) ), nType, BASICIDE_TYPE_MODULE );
14 + OSL_TRACE("pWin->pWin->IsA( TYPE( DialogWindow ) %d && nType %d = BASICIDE_TYPE_DIALOG %d", pWin->IsA( TYPE( DialogWindow ) ), nType, BASICIDE_TYPE_DIALOG );
15 + if ( pWin->GetLibName() == rLibName && pWin->GetName() == rName &&
16 ( ( pWin->IsA( TYPE( ModulWindow ) ) && nType == BASICIDE_TYPE_MODULE ) ||
17 ( pWin->IsA( TYPE( DialogWindow ) ) && nType == BASICIDE_TYPE_DIALOG ) ) )
18 - {
19 return pWin;
22 --- basctl/source/basicide/basides2.cxx.old 2009-04-02 10:56:36.000000000 +0000
23 +++ basctl/source/basicide/basides2.cxx 2009-04-06 16:41:59.000000000 +0000
24 @@ -251,9 +251,12 @@ ModulWindow* BasicIDEShell::CreateBasWin
26 if ( bSuccess )
28 - // new module window
29 - pWin = new ModulWindow( pModulLayout, rDocument, aLibName, aModName, aModule );
30 - nKey = InsertWindowInTable( pWin );
31 + pWin = FindBasWin( rDocument, aLibName, aModName, FALSE, TRUE );
32 + if( !pWin )
33 + { // new module window
34 + pWin = new ModulWindow( pModulLayout, rDocument, aLibName, aModName, aModule );
35 + nKey = InsertWindowInTable( pWin );
36 + }
39 else
40 @@ -268,7 +271,8 @@ ModulWindow* BasicIDEShell::CreateBasWin
42 DBG_ASSERT( nKey, "CreateBasWin: Kein Key- Fenster nicht gefunden!" );
44 - pTabBar->InsertPage( (USHORT)nKey, aModName );
45 + if( nKey )
46 + pTabBar->InsertPage( (USHORT)nKey, aModName );
47 pTabBar->Sort();
48 pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
49 if ( !pCurWin )
50 --- basctl/source/basicide/basidesh.cxx.old 2009-04-02 10:56:36.000000000 +0000
51 +++ basctl/source/basicide/basidesh.cxx 2009-04-06 16:41:59.000000000 +0000
52 @@ -80,6 +80,9 @@
53 #include <com/sun/star/script/XLibraryContainer.hpp>
54 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
55 #include <com/sun/star/container/XNameContainer.hpp>
56 +#include <com/sun/star/container/XContainer.hpp>
57 +#include <com/sun/star/container/XContainerListener.hpp>
58 +#include <com/sun/star/script/XLibraryContainer.hpp>
60 #include <svx/xmlsecctrl.hxx>
62 @@ -87,6 +90,71 @@ using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star;
64 using ::rtl::OUString;
66 +static const rtl::OUString sStandardLibName( rtl::OUString::createFromAscii("Standard") );
68 +typedef ::cppu::WeakImplHelper1< container::XContainerListener > ContainerListenerBASE;
70 +class ContainerListenerImpl : public ContainerListenerBASE
72 + BasicIDEShell* mpShell;
73 +public:
75 + ContainerListenerImpl( BasicIDEShell* pShell ) : mpShell( pShell ) {}
77 + ~ContainerListenerImpl()
78 + {
79 + }
81 + void addContainerListener( const ScriptDocument& rScriptDocument )
82 + {
83 + uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, sStandardLibName, FALSE ), uno::UNO_QUERY );
84 + if ( rScriptDocument.isDocument() && xContainer.is() )
85 + {
86 + uno::Reference< container::XContainerListener > xContainerListener( this );
87 + try
88 + {
89 + xContainer->addContainerListener( xContainerListener );
90 + }
91 + catch( uno::Exception& ) {}
92 + }
93 + }
94 + void removeContainerListener( const ScriptDocument& rScriptDocument )
95 + {
96 + uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, sStandardLibName, FALSE ), uno::UNO_QUERY );
97 + if ( rScriptDocument.isDocument(), xContainer.is() )
98 + {
99 + uno::Reference< container::XContainerListener > xContainerListener( this );
100 + try
102 + xContainer->removeContainerListener( xContainerListener );
104 + catch( uno::Exception& ) {}
108 + // XEventListener
109 + virtual void SAL_CALL disposing( const lang::EventObject& ) throw( uno::RuntimeException ) {}
111 + // XContainerListener
112 + virtual void SAL_CALL elementInserted( const container::ContainerEvent& Event ) throw( uno::RuntimeException )
114 + rtl::OUString sModuleName;
115 + if( mpShell && ( Event.Accessor >>= sModuleName ) )
116 + mpShell->FindBasWin( mpShell->m_aCurDocument, sStandardLibName, sModuleName, TRUE, FALSE );
118 + virtual void SAL_CALL elementReplaced( const container::ContainerEvent& ) throw( com::sun::star::uno::RuntimeException ) { }
119 + virtual void SAL_CALL elementRemoved( const container::ContainerEvent& Event ) throw( com::sun::star::uno::RuntimeException )
121 + rtl::OUString sModuleName;
122 + if( mpShell && ( Event.Accessor >>= sModuleName ) )
124 + IDEBaseWindow* pWin = mpShell->FindWindow( mpShell->m_aCurDocument, sStandardLibName, sModuleName, BASICIDE_TYPE_MODULE, TRUE );
125 + if( pWin )
126 + mpShell->RemoveWindow( pWin, FALSE, TRUE );
132 TYPEINIT1( BasicIDEShell, SfxViewShell );
134 @@ -124,6 +192,7 @@ BasicIDEShell::BasicIDEShell( SfxViewFra
135 m_bAppBasicModified( FALSE ),
136 m_aNotifier( *this )
138 + m_xLibListener = new ContainerListenerImpl( this );
139 Init();
140 GnBasicIDEShellCount++;
142 @@ -215,6 +284,12 @@ __EXPORT BasicIDEShell::~BasicIDEShell()
143 delete pTabBar;
144 delete pObjectCatalog;
145 DestroyModulWindowLayout();
147 + ContainerListenerImpl* pListener = dynamic_cast< ContainerListenerImpl* >( m_xLibListener.get() );
148 + // Destroy all ContainerListeners for Basic Container.
149 + if ( pListener )
150 + pListener->removeContainerListener( m_aCurDocument );
152 // MI: Das gab einen GPF im SDT beim Schliessen da dann der ViewFrame die
153 // ObjSh loslaesst. Es wusste auch keiner mehr wozu das gut war.
154 // GetViewFrame()->GetObjectShell()->Broadcast( SfxSimpleHint( SFX_HINT_DYING ) );
155 @@ -921,7 +996,15 @@ void BasicIDEShell::SetCurLib( const Scr
157 if ( !bCheck || ( rDocument != m_aCurDocument || aLibName != m_aCurLibName ) )
159 + ContainerListenerImpl* pListener = dynamic_cast< ContainerListenerImpl* >( m_xLibListener.get() );
160 + if ( pListener )
161 + pListener->removeContainerListener( m_aCurDocument );
163 m_aCurDocument = rDocument;
165 + if ( pListener )
166 + pListener->addContainerListener( m_aCurDocument );
168 m_aCurLibName = aLibName;
169 if ( bUpdateWindows )
170 UpdateWindows();
171 --- basctl/source/basicide/scriptdocument.cxx.old 2009-04-06 16:41:59.000000000 +0000
172 +++ basctl/source/basicide/scriptdocument.cxx 2009-04-06 16:41:59.000000000 +0000
173 @@ -56,6 +56,7 @@
174 #include <com/sun/star/frame/XModel2.hpp>
175 #include <com/sun/star/awt/XWindow2.hpp>
176 #include <com/sun/star/document/XEmbeddedScripts.hpp>
177 +#include <com/sun/star/script/ModuleInfo.hpp>
178 /** === end UNO includes === **/
180 #include <sfx2/objsh.hxx>
181 @@ -142,6 +143,7 @@ namespace basctl
182 using ::com::sun::star::uno::RuntimeException;
183 using ::com::sun::star::document::XEventBroadcaster;
184 using ::com::sun::star::document::XEmbeddedScripts;
185 + using ::com::sun::star::script::ModuleInfo;
186 /** === end UNO using === **/
187 namespace MacroExecMode = ::com::sun::star::document::MacroExecMode;
188 namespace FrameSearchFlag = ::com::sun::star::frame::FrameSearchFlag;
189 @@ -674,6 +676,15 @@ namespace basctl
192 // insert element by new name in container
193 + if ( _eType == E_SCRIPTS )
195 + ModuleInfo sModuleInfo;
196 + if ( aElement >>= sModuleInfo )
198 + sModuleInfo.ModuleName = _rNewName;
199 + aElement <<= sModuleInfo;
202 xLib->insertByName( _rNewName, aElement );
203 return true;
205 @@ -738,8 +749,16 @@ namespace basctl
206 Reference< XNameContainer > xLib( getOrCreateLibrary( E_SCRIPTS, _rLibName ), UNO_QUERY_THROW );
207 if ( !xLib->hasByName( _rModName ) )
208 return false;
210 - xLib->replaceByName( _rModName, makeAny( _rModuleCode ) );
211 + ModuleInfo mInfo;
212 + Any aMod;
213 + if ( xLib->getByName( _rModName ) >>= mInfo )
215 + mInfo.ModuleSource = _rModuleCode;
216 + aMod <<= mInfo;
218 + else
219 + aMod <<= _rModuleCode;
220 + xLib->replaceByName( _rModName, aMod );
221 return true;
223 catch( const Exception& )
224 @@ -1392,7 +1411,15 @@ namespace basctl
225 Any aCode;
226 if ( !m_pImpl->getModuleOrDialog( E_SCRIPTS, _rLibName, _rModName, aCode ) )
227 return false;
228 - OSL_VERIFY( aCode >>= _out_rModuleSource );
229 + ModuleInfo sModuleInfo;
230 + if ( aCode >>= sModuleInfo )
232 + _out_rModuleSource = sModuleInfo.ModuleSource;
234 + else
236 + OSL_VERIFY( aCode >>= _out_rModuleSource );
238 return true;
241 --- basctl/source/inc/basidesh.hxx.old 2009-04-02 10:56:36.000000000 +0000
242 +++ basctl/source/inc/basidesh.hxx 2009-04-06 16:41:59.000000000 +0000
243 @@ -49,6 +49,7 @@
244 #include <com/sun/star/io/XInputStreamProvider.hpp>
245 #endif
247 +#include <com/sun/star/container/XContainerListener.hpp>
249 //----------------------------------------------------------------------------
251 @@ -107,6 +108,8 @@ friend bool BasicIDE::RemoveDialog( cons
252 BOOL m_bAppBasicModified;
253 ::basctl::DocumentEventNotifier
254 m_aNotifier;
255 +friend class ContainerListenerImpl;
256 + ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener > m_xLibListener;
258 #if _SOLAR__PRIVATE
259 void Init();
260 --- basic/inc/basic/sbmod.hxx.old 2009-04-06 16:41:59.000000000 +0000
261 +++ basic/inc/basic/sbmod.hxx 2009-04-06 16:41:59.000000000 +0000
262 @@ -37,7 +37,7 @@
263 #ifndef _RTL_USTRING_HXX
264 #include <rtl/ustring.hxx>
265 #endif
267 +#include <com/sun/star/script/ModuleType.hpp>
268 class SbMethod;
269 class SbProperty;
270 class SbiRuntime;
271 @@ -67,6 +67,9 @@ protected:
272 SbiBreakpoints* pBreaks; // Breakpoints
273 SbClassData* pClassData;
274 bool mbVBACompat;
275 + INT32 mnType;
276 + SbxObjectRef pDocObject; // an impl object ( used by Document Modules )
277 + bool bIsProxyModule;
279 void StartDefinitions();
280 SbMethod* GetMethod( const String&, SbxDataType );
281 @@ -91,7 +94,7 @@ protected:
282 public:
283 SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_BASICMOD,2);
284 TYPEINFO();
285 - SbModule( const String& );
286 + SbModule( const String&, bool bCompat = false );
287 virtual void SetParent( SbxObject* );
288 virtual void Clear();
290 @@ -127,8 +130,12 @@ public:
291 BOOL LoadBinaryData( SvStream& );
292 BOOL ExceedsLegacyModuleSize();
293 void fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg = NULL ) const;
294 - bool IsVBACompat() { return mbVBACompat; }
295 bool HasExeCode();
296 + bool IsVBACompat();
297 + void SetVBACompat( bool bCompat );
298 + INT32 GetModuleType() { return mnType; }
299 + void SetModuleType( INT32 nType ) { mnType = nType; }
300 + bool GetIsProxyModule() { return bIsProxyModule; }
303 #ifndef __SB_SBMODULEREF_HXX
304 --- basic/inc/basic/sbobjmod.hxx.old 1970-01-01 00:00:00.000000000 +0000
305 +++ basic/inc/basic/sbobjmod.hxx 2009-04-06 16:41:59.000000000 +0000
306 @@ -0,0 +1,66 @@
307 +/*************************************************************************
309 + * OpenOffice.org - a multi-platform office productivity suite
311 + * $RCSfile: sbobjmod.hxx,v $
313 + * $Revision: 1.4 $
315 + * last change: $Author: $ $Date: 2007/08/27 16:31:39 $
317 + * The Contents of this file are made available subject to
318 + * the terms of GNU Lesser General Public License Version 2.1.
321 + * GNU Lesser General Public License Version 2.1
322 + * =============================================
323 + * Copyright 2005 by Sun Microsystems, Inc.
324 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
326 + * This library is free software; you can redistribute it and/or
327 + * modify it under the terms of the GNU Lesser General Public
328 + * License version 2.1, as published by the Free Software Foundation.
330 + * This library is distributed in the hope that it will be useful,
331 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
332 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
333 + * Lesser General Public License for more details.
335 + * You should have received a copy of the GNU Lesser General Public
336 + * License along with this library; if not, write to the Free Software
337 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
338 + * MA 02111-1307 USA
340 + ************************************************************************/
342 +#ifndef _SB_OBJMOD_HXX
343 +#define _SB_OBJMOD_HXX
345 +#include <basic/sbmod.hxx>
346 +#include <basic/sbstar.hxx>
347 +#include <com/sun/star/script/ModuleInfo.hpp>
348 +#include <com/sun/star/lang/XEventListener.hpp>
349 +#include <com/sun/star/awt/XDialog.hpp>
351 +namespace css = ::com::sun::star;
353 +// Basic-Module for excel object.
355 +class SbObjModule : public SbModule
357 +public:
358 + TYPEINFO();
359 + SbObjModule( const com::sun::star::script::ModuleInfo& mInfo, bool bIsVbaCompatible );
360 + virtual SbxVariable* Find( const XubString& rName, SbxClassType t );
361 + SbxVariable* GetObject();
362 + void SetUnoObject( const com::sun::star::uno::Any& aObj )throw ( com::sun::star::uno::RuntimeException ) ;
365 +#ifndef __SB_SBOBJMODULEREF_HXX
366 +#define __SB_SBOBJMODULEREF_HXX
368 +SV_DECL_IMPL_REF(SbObjModule);
370 +#endif
371 +#endif
373 --- basic/inc/basic/sbstar.hxx.old 2009-04-02 10:49:18.000000000 +0000
374 +++ basic/inc/basic/sbstar.hxx 2009-04-06 16:41:59.000000000 +0000
375 @@ -40,6 +40,7 @@
377 #include <basic/sbdef.hxx>
378 #include <basic/sberrors.hxx>
379 +#include <com/sun/star/script/ModuleInfo.hpp>
381 class SbModule; // fertiges Modul
382 class SbiInstance; // Laufzeit-Instanz
383 @@ -71,6 +72,7 @@ class StarBASIC : public SbxObject
384 BOOL bNoRtl; // TRUE: RTL nicht durchsuchen
385 BOOL bBreak; // TRUE: Break, sonst Step
386 BOOL bDocBasic;
387 + BOOL bVBAEnabled;
388 BasicLibInfo* pLibInfo; // Infoblock fuer Basic-Manager
389 SbLanguageMode eLanguageMode; // LanguageMode des Basic-Objekts
390 protected:
391 @@ -113,7 +115,8 @@ public:
393 // Compiler-Interface
394 SbModule* MakeModule( const String& rName, const String& rSrc );
395 - SbModule* MakeModule32( const String& rName, const ::rtl::OUString& rSrc );
396 + SbModule* MakeModule32( const String& rName, const ::rtl::OUString& rSrc );
397 + SbModule* MakeModule32( const com::sun::star::script::ModuleInfo& mInfo );
398 BOOL Compile( SbModule* );
399 BOOL Disassemble( SbModule*, String& rText );
400 static void Stop();
401 @@ -185,6 +188,8 @@ public:
402 ( const String& rName, USHORT& rStatus );
403 static SbMethod* GetActiveMethod( USHORT nLevel = 0 );
404 static SbModule* GetActiveModule();
405 + void SetVBAEnabled( BOOL bEnabled );
406 + BOOL isVBAEnabled();
408 // #60175 TRUE: SFX-Resource wird bei Basic-Fehlern nicht angezogen
409 static void StaticSuppressSfxResource( BOOL bSuppress );
410 --- basic/source/basmgr/basmgr.cxx.old 2009-04-06 16:41:59.000000000 +0000
411 +++ basic/source/basmgr/basmgr.cxx 2009-04-06 16:41:59.000000000 +0000
412 @@ -44,6 +44,7 @@
413 #include <tools/debug.hxx>
414 #include <tools/diagnose_ex.h>
415 #include <basic/sbmod.hxx>
416 +#include <basic/sbobjmod.hxx>
418 #include <basic/sbuno.hxx>
419 #include <basic/basmgr.hxx>
420 @@ -67,6 +68,8 @@
421 #include <com/sun/star/script/XStarBasicDialogInfo.hpp>
422 #include <com/sun/star/script/XStarBasicLibraryInfo.hpp>
423 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
424 +#include <com/sun/star/script/ModuleInfo.hpp>
425 +#include <com/sun/star/script/ModuleType.hpp>
427 #include <cppuhelper/implbase1.hxx>
429 @@ -243,9 +246,18 @@ void BasMgrContainerListenerImpl::addLib
431 ::rtl::OUString aModuleName = pNames[ j ];
432 Any aElement = xLibNameAccess->getByName( aModuleName );
433 - ::rtl::OUString aMod;
434 - aElement >>= aMod;
435 - pLib->MakeModule32( aModuleName, aMod );
436 + ModuleInfo mInfo;
437 + if ( aElement >>= mInfo )
439 + OSL_TRACE("#addLibraryModulesImpl - aMod");
440 + pLib->MakeModule32( mInfo );
442 + else
444 + ::rtl::OUString aMod;
445 + aElement >>= aMod;
446 + pLib->MakeModule32( aModuleName, aMod );
451 @@ -282,8 +294,6 @@ void SAL_CALL BasMgrContainerListenerImp
453 else
455 - ::rtl::OUString aMod;
456 - Event.Element >>= aMod;
458 StarBASIC* pLib = mpMgr->GetLib( maLibName );
459 DBG_ASSERT( pLib, "BasMgrContainerListenerImpl::elementInserted: Unknown lib!");
460 @@ -292,7 +302,17 @@ void SAL_CALL BasMgrContainerListenerImp
461 SbModule* pMod = pLib->FindModule( aName );
462 if( !pMod )
464 - pLib->MakeModule32( aName, aMod );
465 + ModuleInfo mInfo;
466 + if( Event.Element >>= mInfo )
468 + pLib->MakeModule32( mInfo );
470 + else
472 + ::rtl::OUString aMod;
473 + Event.Element >>= aMod;
474 + pLib->MakeModule32( aName, aMod );
476 pLib->SetModified( FALSE );
479 @@ -316,15 +336,35 @@ void SAL_CALL BasMgrContainerListenerImp
480 DBG_ASSERT( !bLibContainer, "library container fired elementReplaced()");
482 StarBASIC* pLib = mpMgr->GetLib( maLibName );
484 if( pLib )
486 - SbModule* pMod = pLib->FindModule( aName );
487 + SbModule* pMod = pLib->FindModule( aName );
488 ::rtl::OUString aMod;
489 - Event.Element >>= aMod;
490 + ModuleInfo mInfo;
491 + if( Event.Element >>= mInfo )
492 + aMod = mInfo.ModuleSource;
493 + else
494 + Event.Element >>= aMod;
495 if( pMod )
497 pMod->SetSource32( aMod );
498 - else
499 - pLib->MakeModule32( aName, aMod );
500 + if ( mInfo.ModuleType == ModuleType::Document )
502 + SbObjModule* pObjModule = dynamic_cast< SbObjModule* >( pMod );
503 + if ( pObjModule )
504 + pObjModule->SetUnoObject( makeAny( mInfo.ModuleObject ) );
507 + else
508 + // Probably we should have an assert for
509 + // unknow module type, e.g. either we are using
510 + // the ModuleInfo structure ( vba ) for *all* modules
511 + // or not ( normal )
512 + if ( mInfo.ModuleType == ModuleType::Unknown )
513 + pLib->MakeModule32( aName, aMod );
514 + else
515 + pLib->MakeModule32( mInfo );
517 pLib->SetModified( FALSE );
519 --- basic/source/classes/sb.cxx.old 2009-04-06 16:41:59.000000000 +0000
520 +++ basic/source/classes/sb.cxx 2009-04-06 16:41:59.000000000 +0000
521 @@ -52,12 +52,17 @@
522 #include "disas.hxx"
523 #include "runtime.hxx"
524 #include <basic/sbuno.hxx>
525 +#include <basic/sbobjmod.hxx>
526 #include "stdobj.hxx"
527 #include "filefmt.hxx"
528 #include "sb.hrc"
529 #include <basrid.hxx>
530 #include <vos/mutex.hxx>
532 +#include <com/sun/star/script/ModuleType.hpp>
533 +#include <com/sun/star/script/ModuleInfo.hpp>
534 +using namespace ::com::sun::star::script;
536 // #pragma SW_SEGMENT_CLASS( SBASIC, SBASIC_CODE )
538 SV_IMPL_VARARR(SbTextPortions,SbTextPortion)
539 @@ -249,6 +254,8 @@ SbxObject* SbiFactory::CreateObject( con
540 else
541 if( rClass.EqualsIgnoreCaseAscii( "Collection" ) )
543 + // Only variables qualified by the Module Name e.g. Sheet1.foo
544 + // should work for Documant && Class type Modules
545 String aCollectionName( RTL_CONSTASCII_USTRINGPARAM("Collection") );
546 return new BasicCollection( aCollectionName );
548 @@ -447,6 +454,7 @@ SbClassModuleObject::SbClassModuleObject
552 + SetModuleType( com::sun::star::script::ModuleType::Class );
555 SbClassModuleObject::~SbClassModuleObject()
556 @@ -582,6 +590,7 @@ StarBASIC::StarBASIC( StarBASIC* p, BOOL
557 SetParent( p );
558 pLibInfo = NULL;
559 bNoRtl = bBreak = FALSE;
560 + bVBAEnabled = FALSE;
561 pModules = new SbxArray;
563 if( !GetSbData()->nInst++ )
564 @@ -684,12 +693,38 @@ SbModule* StarBASIC::MakeModule( const S
566 SbModule* StarBASIC::MakeModule32( const String& rName, const ::rtl::OUString& rSrc )
568 - SbModule* p = new SbModule( rName );
569 - p->SetSource32( rSrc );
570 + ModuleInfo mInfo;
571 + mInfo.ModuleSource = rSrc;
572 + mInfo.ModuleType = ModuleType::Normal;
573 + mInfo.ModuleName = rName;
574 + return MakeModule32( mInfo );
576 +SbModule* StarBASIC::MakeModule32( const ModuleInfo& mInfo )
579 + OSL_TRACE("create module %s type mInfo %d", rtl::OUStringToOString( mInfo.ModuleName, RTL_TEXTENCODING_UTF8 ).getStr(), mInfo.ModuleType );
580 + SbModule* p = NULL;
581 + switch ( mInfo.ModuleType )
583 + case ModuleType::Document:
584 + // In theory we should be able to create Object modules
585 + // in ordinary basic ( in vba mode thought these are create
586 + // by the application/basic and not by the user )
587 + p = new SbObjModule( mInfo, isVBAEnabled() );
588 + break;
589 + case ModuleType::Class:
590 + p = new SbModule( mInfo.ModuleName, isVBAEnabled() );
591 + p->SetModuleType( com::sun::star::script::ModuleType::Class );
592 + break;
593 + default:
594 + p = new SbModule( mInfo.ModuleName, isVBAEnabled() );
597 + p->SetSource32( mInfo.ModuleSource );
598 p->SetParent( this );
599 pModules->Insert( p, pModules->Count() );
600 SetModified( TRUE );
601 - return p;
602 + return p;
605 void StarBASIC::Insert( SbxVariable* pVar )
606 @@ -863,6 +898,12 @@ SbxVariable* StarBASIC::Find( const Stri
608 pNamed = p;
610 + // Only variables qualified by the Module Name e.g. Sheet1.foo
611 + // should work for Documant && Class type Modules
612 + INT32 nType = p->GetModuleType();
613 + //if ( nType == com::sun::star::script::ModuleType::Class || nType == com::sun::star::script::ModuleType::Document )
614 + if ( nType == com::sun::star::script::ModuleType::Document )
615 + continue;
616 // Sonst testen, ob das Element vorhanden ist
617 // GBLSEARCH-Flag rausnehmen (wg. Rekursion)
618 USHORT nGblFlag = p->GetFlags() & SBX_GBLSEARCH;
619 --- basic/source/classes/sbxmod.cxx.old 2009-04-06 16:41:59.000000000 +0000
620 +++ basic/source/classes/sbxmod.cxx 2009-04-06 16:41:59.000000000 +0000
621 @@ -55,6 +55,8 @@
623 #include <basic/basrdll.hxx>
624 #include <vos/mutex.hxx>
625 +#include <basic/sbobjmod.hxx>
626 +#include <com/sun/star/lang/XServiceInfo.hpp>
629 // for the bsearch
630 @@ -70,6 +72,17 @@
632 #include <stdio.h>
634 +#include <comphelper/processfactory.hxx>
635 +#include <com/sun/star/script/XLibraryContainer.hpp>
636 +#include <com/sun/star/lang/XMultiServiceFactory.hpp>
637 +#include <com/sun/star/awt/XDialogProvider.hpp>
638 +#include <com/sun/star/awt/XTopWindow.hpp>
639 +#include <com/sun/star/awt/XControl.hpp>
640 +#include <com/sun/star/frame/XModel.hpp>
641 +#include <cppuhelper/implbase1.hxx>
642 +#include <comphelper/anytostring.hxx>
644 +using namespace ::com::sun::star;
646 TYPEINIT1(SbModule,SbxObject)
647 TYPEINIT1(SbMethod,SbxMethod)
648 @@ -77,6 +90,7 @@ TYPEINIT1(SbProperty,SbxProperty)
649 TYPEINIT1(SbProcedureProperty,SbxProperty)
650 TYPEINIT1(SbJScriptModule,SbModule)
651 TYPEINIT1(SbJScriptMethod,SbMethod)
652 +TYPEINIT1(SbObjModule,SbModule)
654 SV_DECL_VARARR(SbiBreakpoints,USHORT,4,4)
655 SV_IMPL_VARARR(SbiBreakpoints,USHORT)
656 @@ -90,12 +104,13 @@ SV_IMPL_VARARR(HighlightPortions, Highli
657 // Ein BASIC-Modul hat EXTSEARCH gesetzt, damit die im Modul enthaltenen
658 // Elemente von anderen Modulen aus gefunden werden koennen.
660 -SbModule::SbModule( const String& rName )
661 +SbModule::SbModule( const String& rName, bool bVBACompat )
662 : SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASICModule") ) ),
663 - pImage( NULL ), pBreaks( NULL ), pClassData( NULL ), mbVBACompat( false )
664 + pImage( NULL ), pBreaks( NULL ), pClassData( NULL ), mbVBACompat( bVBACompat ), pDocObject( NULL ), bIsProxyModule( false )
666 SetName( rName );
667 SetFlag( SBX_EXTSEARCH | SBX_GBLSEARCH );
668 + SetModuleType( com::sun::star::script::ModuleType::Normal );
671 SbModule::~SbModule()
672 @@ -270,7 +285,10 @@ void SbModule::Clear()
674 SbxVariable* SbModule::Find( const XubString& rName, SbxClassType t )
676 + // make sure a search in an uninstatiated class module will fail
677 SbxVariable* pRes = SbxObject::Find( rName, t );
678 + if ( bIsProxyModule )
679 + return NULL;
680 if( !pRes && pImage )
682 SbiInstance* pInst = pINST;
683 @@ -430,6 +448,7 @@ void SbModule::SetSource32( const ::rtl:
684 aOUSource = r;
685 StartDefinitions();
686 SbiTokenizer aTok( r );
687 + aTok.SetCompatible( IsVBACompat() );
688 while( !aTok.IsEof() )
690 SbiToken eEndTok = NIL;
691 @@ -454,14 +473,6 @@ void SbModule::SetSource32( const ::rtl:
693 eEndTok = ENDPROPERTY; break;
695 - if( eCurTok == OPTION )
697 - eCurTok = aTok.Next();
698 - mbVBACompat = ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) && ( aTok.GetDbl()== 1 );
699 - if( eCurTok == COMPATIBLE
700 - || mbVBACompat )
701 - aTok.SetCompatible( true );
704 eLastTok = eCurTok;
706 @@ -600,10 +611,19 @@ void ClearUnoObjectsInRTL_Impl( StarBASI
707 if( ((StarBASIC*)p) != pBasic )
708 ClearUnoObjectsInRTL_Impl_Rek( (StarBASIC*)p );
710 +bool SbModule::IsVBACompat()
712 + return mbVBACompat;
715 +void SbModule::SetVBACompat( bool bCompat )
717 + mbVBACompat = bCompat;
719 // Ausfuehren eines BASIC-Unterprogramms
720 USHORT SbModule::Run( SbMethod* pMeth )
722 + OSL_TRACE("About to run %s, vba compatmode is %d", rtl::OUStringToOString( pMeth->GetName(), RTL_TEXTENCODING_UTF8 ).getStr(), mbVBACompat );
723 static USHORT nMaxCallLevel = 0;
724 static String aMSOMacroRuntimeLibName = String::CreateFromAscii( "Launcher" );
725 static String aMSOMacroRuntimeAppSymbol = String::CreateFromAscii( "Application" );
726 @@ -695,10 +715,10 @@ USHORT SbModule::Run( SbMethod* pMeth )
727 if( pRt->pNext )
728 pRt->pNext->block();
729 pINST->pRun = pRt;
730 - if ( SbiRuntime ::isVBAEnabled() )
731 + if ( mbVBACompat )
733 pINST->EnableCompatibility( TRUE );
734 - pRt->SetVBAEnabled( true );
735 + //pRt->SetVBAEnabled( true ); // can we get rid of this
737 while( pRt->Step() ) {}
738 if( pRt->pNext )
739 @@ -1273,7 +1293,6 @@ BOOL SbModule::LoadBinaryData( SvStream&
740 return bRet;
744 BOOL SbModule::LoadCompleted()
746 SbxArray* p = GetMethods();
747 @@ -1513,6 +1532,53 @@ SbJScriptMethod::~SbJScriptMethod()
750 /////////////////////////////////////////////////////////////////////////
751 +SbObjModule::SbObjModule( const com::sun::star::script::ModuleInfo& mInfo, bool bIsVbaCompatible )
752 + : SbModule( mInfo.ModuleName, bIsVbaCompatible )
754 + SetModuleType( mInfo.ModuleType );
755 + if ( mInfo.ModuleType == script::ModuleType::Form )
757 + SetClassName( rtl::OUString::createFromAscii( "Form" ) );
759 + else if ( mInfo.ModuleObject.is() )
760 + SetUnoObject( uno::makeAny( mInfo.ModuleObject ) );
762 +void
763 +SbObjModule::SetUnoObject( const uno::Any& aObj ) throw ( uno::RuntimeException )
765 + SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,(SbxVariable*)pDocObject);
766 + if ( pUnoObj && pUnoObj->getUnoAny() == aObj ) // object is equal, nothing to do
767 + return;
768 + pDocObject = new SbUnoObject( GetName(), uno::makeAny( aObj ) );
770 + com::sun::star::uno::Reference< com::sun::star::lang::XServiceInfo > xServiceInfo( aObj, com::sun::star::uno::UNO_QUERY_THROW );
771 + if( xServiceInfo->supportsService( rtl::OUString::createFromAscii( "ooo.vba.excel.Worksheet" ) ) )
773 + SetClassName( rtl::OUString::createFromAscii( "Worksheet" ) );
775 + else if( xServiceInfo->supportsService( rtl::OUString::createFromAscii( "ooo.vba.excel.Workbook" ) ) )
777 + SetClassName( rtl::OUString::createFromAscii( "Workbook" ) );
781 +SbxVariable*
782 +SbObjModule::GetObject()
784 + return pDocObject;
786 +SbxVariable*
787 +SbObjModule::Find( const XubString& rName, SbxClassType t )
789 + //OSL_TRACE("SbObjectModule find for %s", rtl::OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ).getStr() );
790 + SbxVariable* pVar = NULL;
791 + if ( !pVar && pDocObject)
792 + pVar = pDocObject->Find( rName, t );
793 + if ( !pVar )
794 + pVar = SbModule::Find( rName, t );
795 + return pVar;
797 +/////////////////////////////////////////////////////////////////////////
799 SbProperty::SbProperty( const String& r, SbxDataType t, SbModule* p )
800 : SbxProperty( r, t ), pMod( p )
801 --- basic/source/comp/codegen.cxx.old 2009-04-02 10:49:17.000000000 +0000
802 +++ basic/source/comp/codegen.cxx 2009-04-06 16:41:59.000000000 +0000
803 @@ -130,12 +130,12 @@ void SbiCodeGen::Save()
804 // OPTION EXPLICIT-Flag uebernehmen
805 if( pParser->bExplicit )
806 p->SetFlag( SBIMG_EXPLICIT );
807 - if( pParser->IsVBASupportOn() )
808 - p->SetFlag( SBIMG_VBASUPPORT );
810 int nIfaceCount = 0;
811 - if( pParser->bClassModule )
812 + if( rMod.mnType == com::sun::star::script::ModuleType::Class )
814 + OSL_TRACE("COdeGen::save() classmodule processing");
815 + rMod.bIsProxyModule = true;
816 p->SetFlag( SBIMG_CLASSMODULE );
817 pCLASSFAC->AddClassModule( &rMod );
819 @@ -158,6 +158,10 @@ void SbiCodeGen::Save()
820 else
822 pCLASSFAC->RemoveClassModule( &rMod );
823 + // Only a ClassModule can revert to Normal
824 + if ( rMod.mnType == com::sun::star::script::ModuleType::Class )
825 + rMod.mnType = com::sun::star::script::ModuleType::Normal;
826 + rMod.bIsProxyModule = false;
828 if( pParser->bText )
829 p->SetFlag( SBIMG_COMPARETEXT );
830 @@ -240,6 +244,8 @@ void SbiCodeGen::Save()
831 if( nPass == 1 )
832 aPropName = aPropName.Copy( aIfaceName.Len() + 1 );
833 SbProcedureProperty* pProcedureProperty = NULL;
834 + OSL_TRACE("*** getProcedureProperty for thing %s",
835 + rtl::OUStringToOString( aPropName,RTL_TEXTENCODING_UTF8 ).getStr() );
836 pProcedureProperty = rMod.GetProcedureProperty( aPropName, ePropType );
838 if( nPass == 1 )
839 --- basic/source/comp/parser.cxx.old 2009-04-06 16:41:57.000000000 +0000
840 +++ basic/source/comp/parser.cxx 2009-04-06 16:41:59.000000000 +0000
841 @@ -144,7 +144,8 @@ SbiParser::SbiParser( StarBASIC* pb, SbM
842 bNewGblDefs =
843 bSingleLineIf =
844 bExplicit = FALSE;
845 - bClassModule = FALSE;
846 + bClassModule = ( pm->GetModuleType() == com::sun::star::script::ModuleType::Class );
847 + OSL_TRACE("Parser - %s, bClassModule %d", rtl::OUStringToOString( pm->GetName(), RTL_TEXTENCODING_UTF8 ).getStr(), bClassModule );
848 pPool = &aPublics;
849 for( short i = 0; i < 26; i++ )
850 eDefTypes[ i ] = SbxVARIANT; // Kein expliziter Defaulttyp
851 @@ -157,6 +158,10 @@ SbiParser::SbiParser( StarBASIC* pb, SbM
853 rTypeArray = new SbxArray; // Array fuer Benutzerdefinierte Typen
854 rEnumArray = new SbxArray; // Array for Enum types
855 + bVBASupportOn = pm->IsVBACompat();
856 + if ( bVBASupportOn )
857 + EnableCompatibility();
862 @@ -755,8 +760,9 @@ void SbiParser::Option()
864 case CLASSMODULE:
865 bClassModule = TRUE;
866 + aGen.GetModule().SetModuleType( com::sun::star::script::ModuleType::Class );
867 break;
868 - case VBASUPPORT:
869 + case VBASUPPORT: // Option VBASupport used to override the module mode ( in fact this must reset the mode
870 if( Next() == NUMBER )
872 if ( nVal == 1 || nVal == 0 )
873 @@ -764,6 +770,10 @@ void SbiParser::Option()
874 bVBASupportOn = ( nVal == 1 );
875 if ( bVBASupportOn )
876 EnableCompatibility();
877 + // if the module setting is different
878 + // reset it to what the Option tells us
879 + if ( bVBASupportOn != aGen.GetModule().IsVBACompat() )
880 + aGen.GetModule().SetVBACompat( bVBASupportOn );
881 break;
884 --- basic/source/inc/codegen.hxx.old 2009-04-02 10:49:15.000000000 +0000
885 +++ basic/source/inc/codegen.hxx 2009-04-06 16:41:59.000000000 +0000
886 @@ -56,6 +56,7 @@ public:
887 void GenStmnt(); // evtl. Statement-Opcode erzeugen
888 UINT32 GetPC();
889 UINT32 GetOffset() { return GetPC() + 1; }
890 + SbModule& GetModule() { return rMod; }
891 void Save();
893 // #29955 for-Schleifen-Ebene pflegen
894 --- basic/source/inc/image.hxx.old 2009-04-02 10:49:15.000000000 +0000
895 +++ basic/source/inc/image.hxx 2009-04-06 16:41:59.000000000 +0000
896 @@ -109,6 +109,5 @@ public:
897 #define SBIMG_COMPARETEXT 0x0002 // OPTION COMPARE TEXT ist aktiv
898 #define SBIMG_INITCODE 0x0004 // Init-Code vorhanden
899 #define SBIMG_CLASSMODULE 0x0008 // OPTION ClassModule is active
900 -#define SBIMG_VBASUPPORT 0x0020 // OPTION VBASupport is 1
902 #endif
903 --- basic/source/runtime/methods1.cxx.old 2009-04-02 10:49:15.000000000 +0000
904 +++ basic/source/runtime/methods1.cxx 2009-04-06 16:41:59.000000000 +0000
905 @@ -44,6 +44,7 @@
906 #ifndef _SBX_HXX
907 #include <basic/sbx.hxx>
908 #endif
909 +#include <basic/sbstar.hxx>
910 #include <svtools/zforlist.hxx>
911 #include <tools/fsys.hxx>
912 #include <tools/urlobj.hxx>
913 @@ -64,6 +65,7 @@
914 #endif
916 #include <vcl/jobset.hxx>
917 +#include <basic/sbobjmod.hxx>
919 #include "sbintern.hxx"
920 #include "runtime.hxx"
921 @@ -2594,14 +2596,14 @@ RTLFUNC(Me)
923 SbModule* pActiveModule = pINST->GetActiveModule();
924 SbClassModuleObject* pClassModuleObject = PTR_CAST(SbClassModuleObject,pActiveModule);
925 + SbxVariableRef refVar = rPar.Get(0);
926 if( pClassModuleObject == NULL )
928 - StarBASIC::Error( SbERR_INVALID_USAGE_OBJECT );
929 + SbObjModule* pMod = PTR_CAST(SbObjModule,pActiveModule);
930 + if ( pMod )
931 + refVar->PutObject( pMod );
933 else
935 - SbxVariableRef refVar = rPar.Get(0);
936 refVar->PutObject( pClassModuleObject );
940 --- basic/source/runtime/runtime.cxx.old 2009-04-06 16:41:58.000000000 +0000
941 +++ basic/source/runtime/runtime.cxx 2009-04-06 16:41:59.000000000 +0000
942 @@ -53,7 +53,8 @@ bool SbiRuntime::isVBAEnabled()
943 bool result = false;
944 SbiInstance* pInst = pINST;
945 if ( pInst && pINST->pRun )
946 - result = pInst->pRun->GetImageFlag( SBIMG_VBASUPPORT );
947 + //result = pInst->pRun->GetImageFlag( SBIMG_VBASUPPORT );
948 + result = pInst->pRun->bVBAEnabled;
949 return result;
952 @@ -64,6 +65,24 @@ void StarBASIC::StaticEnableReschedule(
954 bStaticGlobalEnableReschedule = bReschedule;
956 +void StarBASIC::SetVBAEnabled( BOOL bEnabled )
958 + if ( bDocBasic )
960 + bVBAEnabled = bEnabled;
964 +BOOL StarBASIC::isVBAEnabled()
966 + if ( bDocBasic )
967 + {
968 + if( SbiRuntime::isVBAEnabled() )
969 + return TRUE;
970 + return bVBAEnabled;
972 + return FALSE;
976 struct SbiArgvStack { // Argv stack:
977 @@ -520,6 +539,7 @@ SbiRuntime::SbiRuntime( SbModule* pm, Sb
978 nForLvl = 0;
979 nOps = 0;
980 refExprStk = new SbxArray;
981 + SetVBAEnabled( pMod->IsVBACompat() );
982 #if defined GCC
983 SetParameters( pe ? pe->GetParameters() : (class SbxArray *)NULL );
984 #else
985 @@ -527,7 +547,6 @@ SbiRuntime::SbiRuntime( SbModule* pm, Sb
986 #endif
987 pRefSaveList = NULL;
988 pItemStoreList = NULL;
989 - bVBAEnabled = isVBAEnabled();
992 SbiRuntime::~SbiRuntime()
993 --- basic/source/uno/namecont.cxx.old 2009-04-02 10:49:15.000000000 +0000
994 +++ basic/source/uno/namecont.cxx 2009-04-06 16:41:59.000000000 +0000
995 @@ -76,6 +76,9 @@
996 #include <cppuhelper/exc_hlp.hxx>
997 #include <basic/sbmod.hxx>
999 +#ifndef _COM_SUN_STAR_SCRIPT_MODULEINFO_HPP_
1000 +#include <com/sun/star/script/ModuleInfo.hpp>
1001 +#endif
1003 namespace basic
1005 @@ -155,7 +158,7 @@ void NameContainer::replaceByName( const
1006 throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
1008 Type aAnyType = aElement.getValueType();
1009 - if( mType != aAnyType )
1010 + if( mType != aAnyType && aAnyType != getCppuType( static_cast< ModuleInfo* >( NULL ) ) )
1011 throw IllegalArgumentException();
1013 NameContainerNameMap::iterator aIt = mHashMap.find( aName );
1014 @@ -197,7 +200,7 @@ void NameContainer::insertByName( const
1015 throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
1017 Type aAnyType = aElement.getValueType();
1018 - if( mType != aAnyType )
1019 + if( mType != aAnyType && aAnyType != getCppuType( static_cast< ModuleInfo* >( NULL ) ) )
1020 throw IllegalArgumentException();
1022 NameContainerNameMap::iterator aIt = mHashMap.find( aName );
1023 --- basic/source/uno/scriptcont.cxx.old 2009-04-06 16:41:59.000000000 +0000
1024 +++ basic/source/uno/scriptcont.cxx 2009-04-06 16:41:59.000000000 +0000
1025 @@ -214,7 +214,12 @@ void SAL_CALL SfxScriptLibraryContainer:
1026 xmlscript::ModuleDescriptor aMod;
1027 aMod.aName = aElementName;
1028 aMod.aLanguage = maScriptLanguage;
1029 - aElement >>= aMod.aCode;
1030 + // make sure we export source
1031 + ::com::sun::star::script::ModuleInfo mInfo;
1032 + if ( aElement >>= mInfo )
1033 + aMod.aCode = mInfo.ModuleSource;
1034 + else
1035 + aElement >>= aMod.aCode;
1036 xmlscript::exportScriptModule( xHandler, aMod );
1039 @@ -1171,7 +1176,11 @@ void SfxScriptLibrary::storeResourcesToS
1040 bool SfxScriptLibrary::containsValidModule( const Any& aElement )
1042 OUString sModuleText;
1043 - aElement >>= sModuleText;
1044 + ::com::sun::star::script::ModuleInfo mInfo;
1045 + if ( aElement >>= mInfo )
1046 + sModuleText = mInfo.ModuleSource;
1047 + else
1048 + aElement >>= sModuleText;
1049 return ( sModuleText.getLength() > 0 );
1052 --- sc/inc/servuno.hxx.old 2009-04-02 10:45:43.000000000 +0000
1053 +++ sc/inc/servuno.hxx 2009-04-06 16:41:59.000000000 +0000
1054 @@ -93,8 +93,8 @@ class ScDocShell;
1056 #define SC_SERVICE_FORMULAPARS 38
1057 #define SC_SERVICE_OPCODEMAPPER 39
1059 -#define SC_SERVICE_COUNT 40
1060 +#define SC_SERVICE_VBAOBJECTPROVIDER 40
1061 +#define SC_SERVICE_COUNT 41
1062 #define SC_SERVICE_INVALID USHRT_MAX
1065 --- sc/source/filter/excel/excimp8.cxx.old 2009-04-06 16:41:59.000000000 +0000
1066 +++ sc/source/filter/excel/excimp8.cxx 2009-04-06 16:41:59.000000000 +0000
1067 @@ -102,6 +102,7 @@
1069 #include <com/sun/star/document/XDocumentProperties.hpp>
1070 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
1071 +#include <com/sun/star/script/ModuleInfo.hpp>
1074 using namespace com::sun::star;
1075 @@ -109,8 +110,8 @@ using namespace com::sun::star;
1077 #define INVALID_POS 0xFFFFFFFF
1081 +// defined in docfunc.cxx ( really this needs a new name )
1082 +script::ModuleInfo lcl_InitModuleInfo( SfxObjectShell& rDocSh, String& sModule );
1084 ImportExcel8::ImportExcel8( XclImpRootData& rImpData, SvStream& rStrm ) :
1085 ImportExcel( rImpData, rStrm )
1086 @@ -260,6 +261,7 @@ bool lcl_hasVBAEnabled()
1088 void ImportExcel8::ReadBasic( void )
1090 + //bHasBasic = TRUE;
1091 bHasBasic = TRUE;
1093 SfxObjectShell* pShell = GetDocShell();
1094 @@ -289,6 +291,10 @@ void ImportExcel8::EndSheet( void )
1096 void ImportExcel8::PostDocLoad( void )
1098 + // delay reading basic until sheet object ( codenames etc. ) are read
1100 + if ( bHasBasic )
1101 + ReadBasic();
1102 // #i11776# filtered ranges before outlines and hidden rows
1103 if( pExcRoot->pAutoFilterBuffer )
1104 pExcRoot->pAutoFilterBuffer->Apply();
1105 --- sc/source/ui/docshell/docsh5.cxx.old 2009-04-06 16:41:49.000000000 +0000
1106 +++ sc/source/ui/docshell/docsh5.cxx 2009-04-06 16:41:59.000000000 +0000
1107 @@ -68,6 +68,10 @@
1108 #include "sc.hrc"
1109 #include "waitoff.hxx"
1110 #include "sizedev.hxx"
1111 +#include <basic/sbstar.hxx>
1113 +// defined in docfunc.cxx
1114 +void lcl_InsertModule( ScDocShell& rDocSh, SCTAB nTab, String& sModuleName, String& sModuleSource );
1116 // ---------------------------------------------------------------------------
1118 @@ -838,6 +842,33 @@ BOOL ScDocShell::MoveTable( SCTAB nSrcTa
1119 GetUndoManager()->AddUndoAction(
1120 new ScUndoCopyTab( this, aSrcList, aDestList ) );
1123 + StarBASIC* pStarBASIC = GetBasic();
1124 + BOOL bVbaEnabled = pStarBASIC ? pStarBASIC->isVBAEnabled() : FALSE;
1125 + if ( bVbaEnabled )
1127 + String sCodeName;
1128 + String sSource;
1129 + aDocument.GetCodeName( nDestTab, sCodeName );
1130 + com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibContainer = GetBasicContainer();
1131 + com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xLib;
1132 + if( xLibContainer.is() )
1134 + String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
1135 + com::sun::star::uno::Any aLibAny = xLibContainer->getByName( aLibName );
1136 + aLibAny >>= xLib;
1138 + if( xLib.is() )
1140 + String sSrcCodeName;
1141 + aDocument.GetCodeName( nSrcTab, sSrcCodeName );
1142 + rtl::OUString sModName = sSrcCodeName;
1143 + com::sun::star::script::ModuleInfo sModuleInfo;
1144 + xLib->getByName( sModName ) >>= sModuleInfo;
1145 + sSource = sModuleInfo.ModuleSource;
1146 + }
1147 + lcl_InsertModule( *this, nDestTab, sCodeName, sSource );
1151 Broadcast( ScTablesHint( SC_TAB_COPIED, nSrcTab, nDestTab ) );
1152 --- sc/source/filter/excel/read.cxx.old 2009-04-06 16:41:51.000000000 +0000
1153 +++ sc/source/filter/excel/read.cxx 2009-04-06 16:41:59.000000000 +0000
1154 @@ -949,7 +949,8 @@ FltError ImportExcel8::Read( void )
1155 case 0x22: Rec1904(); break; // 1904 [ 2345 ]
1156 case 0x56: Builtinfmtcnt(); break; // BUILTINFMTCNT[ 34 ]
1157 case 0x8D: Hideobj(); break; // HIDEOBJ [ 345 ]
1158 - case 0xD3: ReadBasic(); break;
1159 + case 0xD3: /*ReadBasic()*/bHasBasic = true; break;
1160 +// case 0xD3: ReadBasic(); break;
1161 case 0xDE: Olesize(); break;
1162 case 0x01BA: Codename( TRUE ); break;
1164 --- sc/source/ui/docshell/docfunc.cxx.old 2009-04-06 16:41:59.000000000 +0000
1165 +++ sc/source/ui/docshell/docfunc.cxx 2009-04-06 16:41:59.000000000 +0000
1166 @@ -51,6 +51,12 @@
1167 #include <svtools/zforlist.hxx>
1168 #include <svtools/PasswordHelper.hxx>
1170 +#include <basic/sbstar.hxx>
1171 +#include <com/sun/star/container/XNameContainer.hpp>
1172 +#include <com/sun/star/script/XLibraryContainer.hpp>
1173 +#include <com/sun/star/script/ModuleInfo.hpp>
1174 +#include <com/sun/star/script/ModuleType.hpp>
1176 #include <list>
1178 #include "docfunc.hxx"
1179 @@ -99,6 +105,7 @@
1180 using namespace com::sun::star;
1181 using ::com::sun::star::uno::Sequence;
1184 // STATIC DATA -----------------------------------------------------------
1186 //========================================================================
1187 @@ -2281,6 +2288,92 @@ BOOL ScDocFunc::MoveBlock( const ScRange
1190 //------------------------------------------------------------------------
1191 +uno::Reference< uno::XInterface > GetDocModuleObject( SfxObjectShell& rDocSh, String& sCodeName )
1193 + uno::Reference< lang::XMultiServiceFactory> xSF(rDocSh.GetModel(), uno::UNO_QUERY);
1194 + uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess;
1195 + uno::Reference< uno::XInterface > xDocModuleApiObject;
1196 + if ( xSF.is() )
1198 + xVBACodeNamedObjectAccess.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAObjectModuleObjectProvider"))), uno::UNO_QUERY );
1199 + xDocModuleApiObject.set( xVBACodeNamedObjectAccess->getByName( sCodeName ), uno::UNO_QUERY );
1201 + return xDocModuleApiObject;
1205 +script::ModuleInfo lcl_InitModuleInfo( SfxObjectShell& rDocSh, String& sModule, String& sSource )
1207 + ::rtl::OUString aModName( sModule );
1208 + ::rtl::OUString sVbaOption( RTL_CONSTASCII_USTRINGPARAM( "Rem Attribute VBA_ModuleType=VBADocumentModule\nOption VBASupport 1\n" ));
1209 + script::ModuleInfo sModuleInfo;
1210 + sModuleInfo.ModuleName = aModName;
1211 + if ( sSource.Len() > 0 )
1212 + sModuleInfo.ModuleSource = sSource;
1213 + else
1214 + sModuleInfo.ModuleSource = sVbaOption;
1215 + sModuleInfo.ModuleType = script::ModuleType::Document;
1216 + sModuleInfo.ModuleObject = GetDocModuleObject( rDocSh, sModule );
1217 + return sModuleInfo;
1220 +void lcl_InsertModule( ScDocShell& rDocSh, SCTAB nTab, String& sModuleName, String& sSource )
1222 + SFX_APP()->EnterBasicCall();
1223 + script::ModuleInfo sModuleInfo = lcl_InitModuleInfo( rDocSh, sModuleName, sSource );
1224 + uno::Reference< script::XLibraryContainer > xLibContainer = rDocSh.GetBasicContainer();
1225 + DBG_ASSERT( xLibContainer.is(), "No BasicContainer!" );
1227 + uno::Reference< container::XNameContainer > xLib;
1228 + if( xLibContainer.is() )
1230 + String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
1231 + uno::Any aLibAny = xLibContainer->getByName( aLibName );
1232 + aLibAny >>= xLib;
1234 + if( xLib.is() )
1236 + // if the Module with codename exists then find a new name
1237 + sal_Int32 nNum = 1;
1238 + sModuleInfo.ModuleName = sModuleName;
1239 + while( xLib->hasByName( sModuleInfo.ModuleName ) )
1241 + sModuleInfo.ModuleName = rtl::OUString::createFromAscii( "Sheet" ) + rtl::OUString::valueOf( nNum );
1242 + nNum += 1;
1244 + uno::Any aSourceAny;
1245 + aSourceAny <<= sModuleInfo;
1246 + xLib->insertByName( sModuleInfo.ModuleName, aSourceAny );
1247 + ScDocument* pDoc = rDocSh.GetDocument();
1248 + String sCodeName( sModuleInfo.ModuleName );
1249 + pDoc->SetCodeName( nTab, sCodeName );
1251 + SFX_APP()->LeaveBasicCall();
1254 +void lcl_DeleteModule( ScDocShell& rDocSh, String& sModuleName )
1256 + SFX_APP()->EnterBasicCall();
1257 + uno::Reference< script::XLibraryContainer > xLibContainer = rDocSh.GetBasicContainer();
1258 + DBG_ASSERT( xLibContainer.is(), "No BasicContainer!" );
1260 + uno::Reference< container::XNameContainer > xLib;
1261 + if( xLibContainer.is() )
1263 + String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
1264 + uno::Any aLibAny = xLibContainer->getByName( aLibName );
1265 + aLibAny >>= xLib;
1267 + if( xLib.is() )
1269 + if( xLib->hasByName( sModuleName ) )
1271 + xLib->removeByName( sModuleName );
1274 + SFX_APP()->LeaveBasicCall();
1278 BOOL ScDocFunc::InsertTable( SCTAB nTab, const String& rName, BOOL bRecord, BOOL bApi )
1280 @@ -2290,8 +2383,18 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab,
1281 ScDocShellModificator aModificator( rDocShell );
1283 ScDocument* pDoc = rDocShell.GetDocument();
1284 - if (bRecord && !pDoc->IsUndoEnabled())
1285 + // Strange loop, also basic is loaded too early ( InsertTable )
1286 + // is called via the xml import for sheets in described in odf
1287 + BOOL bInsertDocModule = false;
1289 + if( !rDocShell.GetDocument()->IsImportingXML() )
1291 + StarBASIC* pStarBASIC = rDocShell.GetBasic();
1292 + bInsertDocModule = pStarBASIC ? pStarBASIC->isVBAEnabled() : false;
1294 + if ( bInsertDocModule || ( bRecord && !pDoc->IsUndoEnabled() ) )
1295 bRecord = FALSE;
1297 if (bRecord)
1298 pDoc->BeginDrawUndo(); // InsertTab erzeugt ein SdrUndoNewPage
1300 @@ -2302,10 +2405,19 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab,
1302 if (pDoc->InsertTab( nTab, rName ))
1304 + String sCodeName;
1305 if (bRecord)
1306 rDocShell.GetUndoManager()->AddUndoAction(
1307 new ScUndoInsertTab( &rDocShell, nTab, bAppend, rName));
1308 // Views updaten:
1309 + // Only insert vba modules if vba mode ( and not currently importing XML )
1310 + if( bInsertDocModule )
1312 + if ( sCodeName.Len() == 0 )
1313 + sCodeName = rName;
1314 + String sSource;
1315 + lcl_InsertModule( rDocShell, nTab, sCodeName, sSource );
1317 rDocShell.Broadcast( ScTablesHint( SC_TAB_INSERTED, nTab ) );
1319 rDocShell.PostPaintExtras();
1320 @@ -2327,8 +2439,12 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab,
1322 BOOL bSuccess = FALSE;
1323 ScDocument* pDoc = rDocShell.GetDocument();
1324 + StarBASIC* pStarBASIC = rDocShell.GetBasic();
1325 + BOOL bVbaEnabled = pStarBASIC->isVBAEnabled();
1326 if (bRecord && !pDoc->IsUndoEnabled())
1327 bRecord = FALSE;
1328 + if ( bVbaEnabled )
1329 + bRecord = FALSE;
1330 BOOL bWasLinked = pDoc->IsLinked(nTab);
1331 ScDocument* pUndoDoc = NULL;
1332 ScRefUndoData* pUndoData = NULL;
1333 @@ -2369,6 +2485,8 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab,
1334 pUndoData = new ScRefUndoData( pDoc );
1337 + String sCodeName;
1338 + BOOL bHasCodeName = pDoc->GetCodeName( nTab, sCodeName );
1339 if (pDoc->DeleteTab( nTab, pUndoDoc ))
1341 if (bRecord)
1342 @@ -2379,6 +2497,13 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab,
1343 new ScUndoDeleteTab( &rDocShell, theTabs, pUndoDoc, pUndoData ));
1345 // Views updaten:
1346 + if( bVbaEnabled )
1348 + if( bHasCodeName )
1350 + lcl_DeleteModule( rDocShell, sCodeName );
1353 rDocShell.Broadcast( ScTablesHint( SC_TAB_DELETED, nTab ) );
1355 if (bWasLinked)
1356 --- sc/source/ui/unoobj/servuno.cxx.old 2009-04-02 10:45:26.000000000 +0000
1357 +++ sc/source/ui/unoobj/servuno.cxx 2009-04-06 16:41:59.000000000 +0000
1358 @@ -38,6 +38,7 @@
1359 #include <svx/unofill.hxx>
1360 #include <svx/unonrule.hxx>
1361 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
1362 +#include <com/sun/star/container/XNameAccess.hpp>
1364 #include "servuno.hxx"
1365 #include "unonames.hxx"
1366 @@ -61,8 +62,103 @@
1367 #include <svx/xmleohlp.hxx>
1368 #include <svx/xmlgrhlp.hxx>
1370 +#include <comphelper/processfactory.hxx>
1372 using namespace ::com::sun::star;
1374 +class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
1376 + uno::Any maWorkbook;
1377 + uno::Any maCachedObject;
1378 + uno::Reference<lang::XMultiServiceFactory> mxSF;
1379 + ScDocShell* mpDocShell;
1380 +public:
1381 + ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
1383 + mxSF.set(comphelper::getProcessServiceFactory());
1384 + uno::Reference<beans::XPropertySet> xProps(mxSF, uno::UNO_QUERY);
1385 + if( xProps.is() )
1387 + ScDocument* pDoc = mpDocShell->GetDocument();
1388 + if ( !pDoc )
1389 + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("")), uno::Reference< uno::XInterface >() );
1391 + uno::Sequence< uno::Any > aArgs(2);
1392 + aArgs[0] = uno::Any( uno::Reference< uno::XInterface >() );
1393 + aArgs[1] = uno::Any( mpDocShell->GetModel() );
1394 + maWorkbook <<= mxSF->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Workbook") ), aArgs );
1398 + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException )
1400 + maCachedObject = uno::Any(); // clear cached object
1401 + String sName = aName;
1402 + ScDocument* pDoc = mpDocShell->GetDocument();
1403 + if ( !pDoc )
1404 + throw uno::RuntimeException();
1405 + if ( sName == pDoc->GetCodeName() )
1406 + maCachedObject = maWorkbook;
1407 + else
1409 + String sCodeName;
1410 + SCTAB nCount = pDoc->GetTableCount();
1411 + for( SCTAB i = 0; i < nCount; i++ )
1413 + pDoc->GetCodeName( i, sCodeName );
1414 + if( sCodeName == sName )
1416 + String sSheetName;
1417 + if( pDoc->GetName( i, sSheetName ) )
1419 + uno::Reference< frame::XModel > xModel( mpDocShell->GetModel() );
1420 + uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
1421 + uno::Reference<sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
1422 + uno::Reference< container::XIndexAccess > xIndexAccess( xSheets, uno::UNO_QUERY_THROW );
1423 + uno::Reference< sheet::XSpreadsheet > xSheet( xIndexAccess->getByIndex( i ), uno::UNO_QUERY_THROW );
1424 + uno::Sequence< uno::Any > aArgs(3);
1425 + aArgs[0] = maWorkbook;
1426 + aArgs[1] = uno::Any( xModel );
1427 + aArgs[2] = uno::Any( rtl::OUString( sSheetName ) );
1428 + maCachedObject <<= mxSF->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Worksheet") ), aArgs );
1429 + break;
1434 + return maCachedObject.hasValue();
1437 + ::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)
1439 + OSL_TRACE("ScVbaObjectForCodeNameProvider::getByName( %s )",
1440 + rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() );
1441 + if ( !hasByName( aName ) )
1442 + throw ::com::sun::star::container::NoSuchElementException();
1443 + return maCachedObject;
1445 + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (::com::sun::star::uno::RuntimeException)
1447 + ScDocument* pDoc = mpDocShell->GetDocument();
1448 + if ( !pDoc )
1449 + throw uno::RuntimeException();
1450 + SCTAB nCount = pDoc->GetTableCount();
1451 + uno::Sequence< rtl::OUString > aNames( nCount + 1 );
1452 + SCTAB index = 0;
1453 + String sCodeName;
1454 + for( ; index < nCount; ++index )
1456 + pDoc->GetCodeName( index, sCodeName );
1457 + aNames[ index ] = sCodeName;
1459 + aNames[ index ] = pDoc->GetCodeName();
1460 + return aNames;
1462 + // XElemenAccess
1463 + virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException){ return uno::Type(); }
1464 + virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException ) { return sal_True; }
1468 //------------------------------------------------------------------------
1470 @@ -112,7 +208,8 @@ static const sal_Char* __FAR_DATA aProvN
1472 SC_SERVICENAME_CHDATAPROV, // SC_SERVICE_CHDATAPROV
1473 SC_SERVICENAME_FORMULAPARS, // SC_SERVICE_FORMULAPARS
1474 - SC_SERVICENAME_OPCODEMAPPER // SC_SERVICE_OPCODEMAPPER
1475 + SC_SERVICENAME_OPCODEMAPPER, // SC_SERVICE_OPCODEMAPPER
1476 +"ooo.vba.VBAObjectModuleObjectProvider",// SC_SERVICE_VBAOBJECTPROVIDER
1480 @@ -164,7 +261,8 @@ static const sal_Char* __FAR_DATA aOldNa
1481 "", // SC_SERVICE_SHEETDOCSET
1482 "", // SC_SERVICE_CHDATAPROV
1483 "", // SC_SERVICE_FORMULAPARS
1484 - "" // SC_SERVICE_OPCODEMAPPER
1485 + "", // SC_SERVICE_OPCODEMAPPER
1486 + "", // SC_SERVICE_VBAOBJECTPROVIDER
1490 @@ -363,6 +461,9 @@ uno::Reference<uno::XInterface> ScServic
1491 xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj(::std::auto_ptr<formula::FormulaCompiler> (pComp))));
1493 break;
1494 + case SC_SERVICE_VBAOBJECTPROVIDER:
1495 + xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
1496 + break;
1498 return xRet;
1500 --- sc/source/ui/view/viewfun2.cxx.old 2009-04-06 16:41:49.000000000 +0000
1501 +++ sc/source/ui/view/viewfun2.cxx 2009-04-06 16:41:59.000000000 +0000
1502 @@ -57,6 +57,11 @@
1503 #include <vcl/sound.hxx>
1504 #include <vcl/waitobj.hxx>
1506 +#include <basic/sbstar.hxx>
1507 +#include <com/sun/star/container/XNameContainer.hpp>
1508 +#include <com/sun/star/script/XLibraryContainer.hpp>
1509 +using namespace com::sun::star;
1511 #include "viewfunc.hxx"
1513 #include "sc.hrc"
1514 @@ -2139,15 +2144,42 @@ BOOL ScViewFunc::DeleteTable( SCTAB nTab
1515 return bSuccess;
1518 +void lcl_DeleteModule( ScDocShell* rDocSh, String& sModuleName )
1520 + SFX_APP()->EnterBasicCall();
1521 + uno::Reference< script::XLibraryContainer > xLibContainer = rDocSh->GetBasicContainer();
1522 + DBG_ASSERT( xLibContainer.is(), "No BasicContainer!" );
1524 + uno::Reference< container::XNameContainer > xLib;
1525 + if( xLibContainer.is() )
1527 + String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
1528 + uno::Any aLibAny = xLibContainer->getByName( aLibName );
1529 + aLibAny >>= xLib;
1531 + if( xLib.is() )
1533 + if( xLib->hasByName( sModuleName ) )
1535 + xLib->removeByName( sModuleName );
1538 + SFX_APP()->LeaveBasicCall();
1541 BOOL ScViewFunc::DeleteTables(const SvShorts &TheTabs, BOOL bRecord )
1543 ScDocShell* pDocSh = GetViewData()->GetDocShell();
1544 ScDocument* pDoc = pDocSh->GetDocument();
1545 + StarBASIC* pStarBASIC = pDocSh->GetBasic();
1546 + BOOL bVbaEnabled = pStarBASIC->isVBAEnabled();
1547 SCTAB nNewTab = TheTabs[0];
1548 int i;
1549 WaitObject aWait( GetFrameWin() );
1550 if (bRecord && !pDoc->IsUndoEnabled())
1551 bRecord = FALSE;
1552 + if ( bVbaEnabled )
1553 + bRecord = FALSE;
1555 while ( nNewTab > 0 && !pDoc->IsVisible( nNewTab ) )
1556 --nNewTab;
1557 @@ -2214,9 +2246,18 @@ BOOL ScViewFunc::DeleteTables(const SvSh
1559 for(i=TheTabs.Count()-1;i>=0;i--)
1561 + String sCodeName;
1562 + BOOL bHasCodeName = pDoc->GetCodeName( TheTabs[sal::static_int_cast<USHORT>(i)], sCodeName );
1563 if (pDoc->DeleteTab( TheTabs[sal::static_int_cast<USHORT>(i)], pUndoDoc ))
1565 bDelDone = TRUE;
1566 + if( bVbaEnabled )
1568 + if( bHasCodeName )
1570 + lcl_DeleteModule( pDocSh, sCodeName );
1573 pDocSh->Broadcast( ScTablesHint( SC_TAB_DELETED, TheTabs[sal::static_int_cast<USHORT>(i)] ) );
1576 @@ -2244,6 +2285,7 @@ BOOL ScViewFunc::DeleteTables(const SvSh
1577 pDocSh->PostPaintExtras();
1578 pDocSh->SetDocumentModified();
1581 SfxApplication* pSfxApp = SFX_APP(); // Navigator
1582 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1583 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
1584 --- svx/source/msfilter/msvbasic.cxx.old 2009-04-02 11:03:03.000000000 +0000
1585 +++ svx/source/msfilter/msvbasic.cxx 2009-04-06 16:41:59.000000000 +0000
1586 @@ -41,6 +41,8 @@
1587 #include <rtl/tencinfo.h> //rtl_getTextEncodingFromWindowsCodePage
1588 #include "msvbasic.hxx"
1590 +using namespace ::com::sun::star::script;
1593 A few urls which may in the future be of some use
1594 http://www.virusbtn.com/vb2000/Programme/papers/bontchev.pdf
1595 @@ -432,7 +434,7 @@ int VBA_Impl::ReadVBAProject(const SvSto
1599 -ModuleType VBA_Impl::GetModuleType( const UniString& rModuleName )
1600 +ModType VBA_Impl::GetModuleType( const UniString& rModuleName )
1602 ModuleTypeHash::iterator iter = mhModHash.find( rModuleName );
1603 ModuleTypeHash::iterator iterEnd = mhModHash.end();
1604 @@ -440,7 +442,7 @@ ModuleType VBA_Impl::GetModuleType( cons
1606 return iter->second;
1608 - return Unknown;
1609 + return ModuleType::Unknown;
1612 bool VBA_Impl::Open( const String &rToplevel, const String &rSublevel )
1613 @@ -483,7 +485,7 @@ bool VBA_Impl::Open( const String &rTopl
1614 static const String sClass( RTL_CONSTASCII_USTRINGPARAM( "Class" ) );
1615 static const String sBaseClass( RTL_CONSTASCII_USTRINGPARAM( "BaseClass" ) );
1616 static const String sDocument( RTL_CONSTASCII_USTRINGPARAM( "Document" ) );
1617 - mhModHash[ sThisDoc ] = Class;
1618 + mhModHash[ sThisDoc ] = ModuleType::Class;
1619 while ( pStp->ReadByteStringLine( tmp, meCharSet ) )
1621 xub_StrLen index = tmp.Search( '=' );
1622 @@ -493,14 +495,14 @@ bool VBA_Impl::Open( const String &rTopl
1623 String value = tmp.Copy( index + 1 );
1624 if ( key == sClass )
1626 - mhModHash[ value ] = Class;
1627 + mhModHash[ value ] = ModuleType::Class;
1628 OSL_TRACE("Module %s is of type Class",
1629 ::rtl::OUStringToOString( value ,
1630 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
1632 else if ( key == sBaseClass )
1634 - mhModHash[ value ] = Form;
1635 + mhModHash[ value ] = ModuleType::Form;
1636 OSL_TRACE("Module %s is of type Form",
1637 ::rtl::OUStringToOString( value ,
1638 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
1639 @@ -513,14 +515,14 @@ bool VBA_Impl::Open( const String &rTopl
1640 // value is of form <name>/&H<identifier>, strip the identifier
1641 value.Erase( value.Search( '/' ) );
1643 - mhModHash[ value ] = Document;
1644 + mhModHash[ value ] = ModuleType::Document;
1645 OSL_TRACE("Module %s is of type Document VBA",
1646 ::rtl::OUStringToOString( value ,
1647 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
1649 else if ( key == sModule )
1651 - mhModHash[ value ] = Normal;
1652 + mhModHash[ value ] = ModuleType::Normal;
1653 OSL_TRACE("Module %s is of type Normal VBA",
1654 ::rtl::OUStringToOString( value ,
1655 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
1656 --- svx/source/msfilter/msvbasic.hxx.old 2009-04-02 11:03:03.000000000 +0000
1657 +++ svx/source/msfilter/msvbasic.hxx 2009-04-06 16:41:59.000000000 +0000
1658 @@ -45,6 +45,8 @@
1659 #include <vector>
1660 #endif
1661 #include<map>
1662 +#include <com/sun/star/script/ModuleType.hpp>
1663 +using namespace ::com::sun::star::script::ModuleType;
1665 /* class VBA:
1666 * The VBA class provides a set of methods to handle Visual Basic For
1667 @@ -68,13 +70,12 @@ DECLARE_DYNARRAY(StringArray,String *)
1668 // #117718# define internal types to distinguish between
1669 // module types, form, class & normal
1670 // #i37965# DR 2004-12-03: add "Document", used in Excel for macros attached to sheet
1671 -enum ModuleType { Unknown = 0, Normal, Class, Form, Document };
1673 // #117718# define map to hold types of module
1676 +typedef sal_Int32 ModType;
1677 typedef ::std::map< UniString,
1678 - ModuleType > ModuleTypeHash;
1679 + ModType > ModuleTypeHash;
1681 class VBA_Impl
1683 @@ -95,7 +96,7 @@ public:
1684 void Output(int len, const sal_uInt8 *data);
1686 // #117718# member map of module names to types of module
1687 - ModuleType GetModuleType( const UniString& rModuleName );
1688 + ModType GetModuleType( const UniString& rModuleName );
1690 std::vector<String> maReferences;
1691 private:
1692 --- svx/source/msfilter/svxmsbas.cxx.old 2009-04-06 16:41:59.000000000 +0000
1693 +++ svx/source/msfilter/svxmsbas.cxx 2009-04-06 16:41:59.000000000 +0000
1694 @@ -53,6 +53,7 @@ using namespace com::sun::star::awt;
1696 #include <com/sun/star/container/XNameContainer.hpp>
1697 #include <com/sun/star/script/XLibraryContainer.hpp>
1698 +#include <com/sun/star/script/ModuleInfo.hpp>
1699 using namespace com::sun::star::container;
1700 using namespace com::sun::star::script;
1701 using namespace com::sun::star::uno;
1702 @@ -266,8 +267,22 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
1703 Any aLibAny = xLibContainer->getByName( aLibName );
1704 aLibAny >>= xLib;
1706 - if( xLib.is() )
1707 + if( xLib.is() )
1709 + Reference< container::XNameAccess > xVBAObjectForCodeName;
1710 + if ( !bAsComment )
1712 + rDocSh.GetBasic()->SetVBAEnabled( true );
1713 + Reference< XMultiServiceFactory> xSF(rDocSh.GetModel(), UNO_QUERY);
1714 + if ( xSF.is() )
1716 + try
1718 + xVBAObjectForCodeName.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAObjectModuleObjectProvider"))), UNO_QUERY );
1720 + catch( Exception& ) { }
1723 for( UINT16 i=0; i<nStreamCount;i++)
1725 StringArray aDecompressed = aVBA.Decompress(i);
1726 @@ -301,7 +316,7 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
1727 // is the same as the encoding for the names
1728 // that are keys in the map used by GetModuleType method
1729 const String &sOrigVBAModName = aVBA.GetStreamName( i );
1730 - ModuleType mType = aVBA.GetModuleType( sOrigVBAModName );
1731 + ModType mType = aVBA.GetModuleType( sOrigVBAModName );
1733 rtl::OUString sClassRem( RTL_CONSTASCII_USTRINGPARAM( "Rem Attribute VBA_ModuleType=" ) );
1735 @@ -309,23 +324,23 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
1737 switch( mType )
1739 - case Class:
1740 + case ModuleType::Class:
1741 modeTypeComment = sClassRem +
1742 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAClassModule\n" ) );
1743 break;
1744 - case Form:
1745 + case ModuleType::Form:
1746 modeTypeComment = sClassRem +
1747 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAFormModule\n" ) );
1748 break;
1749 - case Document:
1750 + case ModuleType::Document:
1751 modeTypeComment = sClassRem +
1752 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBADocumentModule\n" ) );
1753 break;
1754 - case Normal:
1755 + case ModuleType::Normal:
1756 modeTypeComment = sClassRem +
1757 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAModule\n" ) );
1758 break;
1759 - case Unknown:
1760 + case ModuleType::Unknown:
1761 modeTypeComment = sClassRem +
1762 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAUnknown\n" ) );
1763 break;
1764 @@ -335,10 +350,10 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
1766 static ::rtl::OUString sVBAOption( RTL_CONSTASCII_USTRINGPARAM( "Option VBASupport 1\n" ) );
1767 static ::rtl::OUString sClassOption( RTL_CONSTASCII_USTRINGPARAM( "Option ClassModule\n" ) );
1768 - if ( !bAsComment )
1769 + if ( !bAsComment /*&& !rDocSh.GetBasic()->isVBAEnabled() */)
1771 modeTypeComment = modeTypeComment + sVBAOption;
1772 - if ( mType == Class )
1773 + if ( mType == ModuleType::Class )
1774 modeTypeComment = modeTypeComment + sClassOption;
1777 @@ -405,12 +420,41 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
1778 aSource += rtl::OUString::createFromAscii("\nEnd Sub");
1780 ::rtl::OUString aModName( sModule );
1781 - if ( aSource.getLength() )
1783 aSource = modeTypeComment + aSource;
1785 Any aSourceAny;
1786 - aSourceAny <<= aSource;
1787 + OSL_TRACE("erm %d", mType );
1788 + if ( !bAsComment )
1790 + OSL_TRACE("vba processing %d", mType );
1791 + script::ModuleInfo sModuleInfo;
1792 + sModuleInfo.ModuleName = aModName;
1793 + sModuleInfo.ModuleSource = aSource;
1794 + sModuleInfo.ModuleType = mType;
1795 + if ( mType == ModuleType::Form )
1796 + // hack, the module ( imo document basic should...
1797 + // know the XModel... ) but it doesn't
1798 + sModuleInfo.ModuleObject.set( rDocSh.GetModel(), UNO_QUERY );
1799 + // document modules, we should be able to access
1800 + // the api objects at this time
1801 + else if ( mType == ModuleType::Document )
1803 + uno::Reference< lang::XMultiServiceFactory> xSF( rDocSh.GetModel(), uno::UNO_QUERY);
1804 + uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess;
1805 + if ( xSF.is() )
1806 + xVBACodeNamedObjectAccess.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAObjectModuleObjectProvider"))), uno::UNO_QUERY );
1807 + // get the api object for the codename
1808 + if ( xVBACodeNamedObjectAccess.is() )
1810 + sModuleInfo.ModuleObject.set( xVBACodeNamedObjectAccess->getByName( sModuleInfo.ModuleName ), uno::UNO_QUERY );
1811 + OSL_TRACE("** Straight up creation of Module");
1814 + aSourceAny <<= sModuleInfo;
1816 + else
1817 + aSourceAny <<= aSource;
1818 if( xLib->hasByName( aModName ) )
1819 xLib->replaceByName( aModName, aSourceAny );
1820 else
1821 @@ -420,6 +464,7 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
1822 bRet = true;
1825 + if( bRet )
1826 SFX_APP()->LeaveBasicCall();
1828 return bRet;
1829 --- udkapi/com/sun/star/script/ModuleInfo.idl.old 1970-01-01 00:00:00.000000000 +0000
1830 +++ udkapi/com/sun/star/script/ModuleInfo.idl 2009-04-06 16:41:59.000000000 +0000
1831 @@ -0,0 +1,57 @@
1832 +/*************************************************************************
1834 + * OpenOffice.org - a multi-platform office productivity suite
1836 + * $RCSfile: ModuleInfo.idl,v $
1838 + * $Revision: 1.2 $
1840 + * last change: $Author: rt $ $Date: 2006/05/05 10:14:46 $
1842 + * The Contents of this file are made available subject to
1843 + * the terms of GNU Lesser General Public License Version 2.1.
1846 + * GNU Lesser General Public License Version 2.1
1847 + * =============================================
1848 + * Copyright 2005 by Sun Microsystems, Inc.
1849 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
1851 + * This library is free software; you can redistribute it and/or
1852 + * modify it under the terms of the GNU Lesser General Public
1853 + * License version 2.1, as published by the Free Software Foundation.
1855 + * This library is distributed in the hope that it will be useful,
1856 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1857 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1858 + * Lesser General Public License for more details.
1860 + * You should have received a copy of the GNU Lesser General Public
1861 + * License along with this library; if not, write to the Free Software
1862 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
1863 + * MA 02111-1307 USA
1865 + ************************************************************************/
1867 +#ifndef __com_sun_star_script_ModuleInfo_idl__
1868 +#define __com_sun_star_script_ModuleInfo_idl__
1870 +#ifndef __com_sun_star_uno_XInterface_idl__
1871 +#include <com/sun/star/uno/XInterface.idl>
1872 +#endif
1874 +//=============================================================================
1875 +module com { module sun { module star { module script {
1876 +struct ModuleInfo
1878 + string ModuleName;
1879 + string ModuleSource;
1880 + com::sun::star::uno::XInterface ModuleObject;
1881 + short ModuleType; // string?
1884 +//=============================================================================
1886 +}; }; }; };
1888 +#endif
1889 --- udkapi/com/sun/star/script/ModuleType.idl.old 1970-01-01 00:00:00.000000000 +0000
1890 +++ udkapi/com/sun/star/script/ModuleType.idl 2009-04-06 16:41:59.000000000 +0000
1891 @@ -0,0 +1,58 @@
1892 +/*************************************************************************
1894 + * OpenOffice.org - a multi-platform office productivity suite
1896 + * $RCSfile: ModuleType.idl,v $
1898 + * $Revision: 1.2 $
1900 + * last change: $Author: rt $ $Date: 2006/05/05 10:14:46 $
1902 + * The Contents of this file are made available subject to
1903 + * the terms of GNU Lesser General Public License Version 2.1.
1906 + * GNU Lesser General Public License Version 2.1
1907 + * =============================================
1908 + * Copyright 2005 by Sun Microsystems, Inc.
1909 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
1911 + * This library is free software; you can redistribute it and/or
1912 + * modify it under the terms of the GNU Lesser General Public
1913 + * License version 2.1, as published by the Free Software Foundation.
1915 + * This library is distributed in the hope that it will be useful,
1916 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1917 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1918 + * Lesser General Public License for more details.
1920 + * You should have received a copy of the GNU Lesser General Public
1921 + * License along with this library; if not, write to the Free Software
1922 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
1923 + * MA 02111-1307 USA
1925 + ************************************************************************/
1927 +#ifndef __com_sun_star_script_ModuleType_idl__
1928 +#define __com_sun_star_script_ModuleType_idl__
1930 +#ifndef __com_sun_star_uno_XInterface_idl__
1931 +#include <com/sun/star/uno/XInterface.idl>
1932 +#endif
1934 +//=============================================================================
1935 +module com { module sun { module star { module script {
1936 +published constants ModuleType
1938 + const long Unknown = 0;
1939 + const long Normal = 1;
1940 + const long Class = 2;
1941 + const long Form = 3;
1942 + const long Document = 4;
1945 +//=============================================================================
1947 +}; }; }; };
1949 +#endif
1950 --- udkapi/com/sun/star/script/makefile.mk.old 2009-04-02 11:06:58.000000000 +0000
1951 +++ udkapi/com/sun/star/script/makefile.mk 2009-04-06 16:41:59.000000000 +0000
1952 @@ -85,6 +85,8 @@ IDLFILES=\
1953 XScriptEventsAttacher.idl\
1954 XDefaultMethod.idl\
1955 XDefaultProperty.idl\
1956 + ModuleInfo.idl\
1957 + ModuleType.idl\
1959 # ------------------------------------------------------------------
1961 --- sc/source/filter/excel/xiescher.cxx.old 2009-04-06 16:41:59.000000000 +0000
1962 +++ sc/source/filter/excel/xiescher.cxx 2009-04-06 16:41:59.000000000 +0000
1963 @@ -495,7 +495,7 @@ void XclImpDrawObjBase::ProcessSdrObject
1965 if( ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( &rSdrObj, TRUE ) )
1967 - pInfo->SetMacro( XclControlHelper::GetScMacroName( maMacroName ) );
1968 + pInfo->SetMacro( XclControlHelper::GetScMacroName( maMacroName, GetDocShell() ) );
1969 pInfo->SetHlink( maHyperlink );
1972 @@ -1876,7 +1876,7 @@ void XclImpTbxObjBase::SetDffProperties(
1974 bool XclImpTbxObjBase::FillMacroDescriptor( ScriptEventDescriptor& rDescriptor ) const
1976 - return XclControlHelper::FillMacroDescriptor( rDescriptor, DoGetEventType(), GetMacroName() );
1977 + return XclControlHelper::FillMacroDescriptor( rDescriptor, DoGetEventType(), GetMacroName(), GetDocShell() );
1980 void XclImpTbxObjBase::ConvertFont( ScfPropertySet& rPropSet ) const
1981 --- sc/source/filter/excel/xlescher.cxx.old 2009-04-06 16:41:59.000000000 +0000
1982 +++ sc/source/filter/excel/xlescher.cxx 2009-04-06 16:41:59.000000000 +0000
1983 @@ -40,6 +40,11 @@
1984 #include "xlescher.hxx"
1985 #include "globstr.hrc"
1987 +#include <sfx2/objsh.hxx>
1988 +#include <basic/sbstar.hxx>
1989 +#include <basic/sbmod.hxx>
1990 +#include <basic/sbmeth.hxx>
1992 using ::rtl::OUString;
1993 using ::com::sun::star::uno::Reference;
1994 using ::com::sun::star::uno::UNO_QUERY;
1995 @@ -302,10 +307,26 @@ Reference< XControlModel > XclControlHel
1996 #define EXC_MACRONAME_PRE "vnd.sun.star.script:Standard."
1997 #define EXC_MACRONAME_SUF "?language=Basic&location=document"
1999 -OUString XclControlHelper::GetScMacroName( const String& rXclMacroName )
2000 +OUString XclControlHelper::GetScMacroName( const String& rXclMacroName, SfxObjectShell* pDocShell )
2002 + String sTmp( rXclMacroName );
2003 if( rXclMacroName.Len() > 0 )
2004 - return CREATE_OUSTRING( EXC_MACRONAME_PRE ) + rXclMacroName + CREATE_OUSTRING( EXC_MACRONAME_SUF );
2006 + if ( ( sTmp.Search( '.' ) == STRING_NOTFOUND) && pDocShell )
2008 + if( StarBASIC* pBasic = pDocShell->GetBasic() )
2010 + if( SbMethod* pMethod = dynamic_cast< SbMethod* >( pBasic->Find( sTmp, SbxCLASS_METHOD ) ) )
2012 + if( SbModule* pModule = pMethod->GetModule() )
2014 + sTmp.Insert( '.', 0 ).Insert( pModule->GetName(), 0 );
2019 + return CREATE_OUSTRING( EXC_MACRONAME_PRE ) + sTmp + CREATE_OUSTRING( EXC_MACRONAME_SUF );
2021 return OUString();
2024 @@ -339,14 +360,14 @@ spTbxListenerData[] =
2025 #define EXC_MACROSCRIPT "Script"
2027 bool XclControlHelper::FillMacroDescriptor( ScriptEventDescriptor& rDescriptor,
2028 - XclTbxEventType eEventType, const String& rXclMacroName )
2029 + XclTbxEventType eEventType, const String& rXclMacroName, SfxObjectShell* pShell )
2031 if( rXclMacroName.Len() > 0 )
2033 rDescriptor.ListenerType = OUString::createFromAscii( spTbxListenerData[ eEventType ].mpcListenerType );
2034 rDescriptor.EventMethod = OUString::createFromAscii( spTbxListenerData[ eEventType ].mpcEventMethod );
2035 rDescriptor.ScriptType = CREATE_OUSTRING( EXC_MACROSCRIPT );
2036 - rDescriptor.ScriptCode = GetScMacroName( rXclMacroName );
2037 + rDescriptor.ScriptCode = GetScMacroName( rXclMacroName, pShell );
2038 return true;
2040 return false;
2041 --- sc/source/filter/inc/xlescher.hxx.old 2009-04-02 10:44:58.000000000 +0000
2042 +++ sc/source/filter/inc/xlescher.hxx 2009-04-06 16:41:59.000000000 +0000
2043 @@ -432,7 +432,8 @@ public:
2044 GetControlModel( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape );
2046 /** Returns the Calc macro name from an Excel macro name. */
2047 - static ::rtl::OUString GetScMacroName( const String& rXclMacroName );
2048 + static ::rtl::OUString GetScMacroName( const String& rXclMacroName, SfxObjectShell* pShell = NULL );
2050 /** Returns the Excel macro name from a Calc macro name. */
2051 static String GetXclMacroName( const ::rtl::OUString& rScMacroName );
2053 @@ -440,7 +441,7 @@ public:
2054 static bool FillMacroDescriptor(
2055 ::com::sun::star::script::ScriptEventDescriptor& rDescriptor,
2056 XclTbxEventType eEventType,
2057 - const String& rXclMacroName );
2058 + const String& rXclMacroName, SfxObjectShell* pShell = NULL );
2059 /** Tries to extract an Excel macro name from the passed macro descriptor. */
2060 static String ExtractFromMacroDescriptor(
2061 const ::com::sun::star::script::ScriptEventDescriptor& rDescriptor,