ODF Document ( loaded ) e.g. via someone accessing the scripts from the BasicContainer sfx2/source/doc/objxtor.cxx o SfxObjectShell::GetBasicContainer() - where the ScriptLibraryContainer ( uno service ) is returned - InitBasicManager_Impl() creates a new BasicManager ( for the document ) o lcl_getOrCreateLibraryContainer, does as the name says on the tin basic - it creates a new SfxScriptLibraryContainer service/instance via the new service uno service thingy 'DocumentScriptLibraryContainer::create( comphelper_getProcessComponentContext(), xStorageDoc )' note: passing the document as a paramater basic/source/uno/scriptcont.cxx o SfxScriptLibraryContainer - is the Library container ( it's the "com.sun.star.script.ScriptLibraryContainer" service XInitialization | XStorageBasedLibraryContainer | XLibraryContainerPassword | XLibraryContainerExport | XContainer | XServiceInfo | LibraryContainerHelper ::utl::OEventListenerAdapter | | ----------------------------- | SfxLibraryContainer OldBasicPassword | | ------------------- | SfxScriptLibraryContainer basic/source/uno/namecont.cxx o SfxLibraryContainer - is the common base class for dialog and script containers - OMG this is a *nasty* class that involves a huge and scary initialisation stack. - it has a maNameContainer member which is more or less a string -> XNameAccess map + SfxLibraryContainer::initialize can call either initializeFromDocumentURL or initializeFromDocument depending on whether a string url or a XStorageBasedDocument instance is passed in. We only care about the latter. + when this class is passed a document storage 'init' is called, which calls init_Impl. There is alot of generic code to deal with the library xml descriptions ( which it seems must to be the same for basic dialogs and basic libraries ), library information is read/parsed into a ::xmlscript::LibDescriptorArray see ( xmlscript/inc/xmlscript/xmllib_imexp.hxx ) struct LibDescriptor { ::rtl::OUString aName; ::rtl::OUString aStorageURL; sal_Bool bLink; sal_Bool bReadOnly; sal_Bool bPasswordProtected; ::com::sun::star::uno::Sequence< ::rtl::OUString > aElementNames; sal_Bool bPreload; }; struct LibDescriptorArray { LibDescriptor* mpLibs; sal_Int32 mnLibCount; }; ignoring links ( which are presumably handled similary ) createLink is called which inturn calls script library specific processing via the implCreateLibrary method ( basic/source/uno/scriptconf.cxx ) The dialog or script library ( XNameAccess ) implementation is returned, note: these are both derived from SfxLibrary. On load it seems actually no library is read[1], instead dummy entries are provided for each of the LibDescriptor entries. [1] part of the init_impl method loops through the LibDescriptor entries and call( class SfxLibraryContainer::loadLibrary ) on any library required to be pre-loaded ( determined by and xml attribute ). The loadLibrary routine calls ( in the case of basic libraries ) SfxScriptLibraryContainer::importLibraryElement() ( scriptcont.cxx ) which does the xml parse of the Module file o SfxScriptLibraryContainer::importLibraryElement Quesion: Is this a good place to read/write a vba option :-/ I think it might, perhaps this is also a place to hook in some codename -> ( associated document object ) relationship without going into the document format itself. Perhaps though the basic manager itself might be better because otherwise we would be ( potentially ) supporting a vba option in the dialog _and_ library xml which doesn't make sense. XNameContainer XContainer cppu::BaseMutex cppu::OComponentHelper | | | | ------------------------------------------------- | SfxLibrary ( basic/source/namecont.cxx ) | SfxScriptLibrary ( basic/source/scriptcont.cxx ) so once a library is loaded, it's source is stored in the maNameContainer of the SfxLibrary ( yes just to confuse things both the SfxLibrary and SfxLibraryContainer both has a same named member of the same type. To make things worse they are used al over the same source files. Of course it's not so confusing when you know what is what. Anyway the maNameContainer in both cases is NameContainer ( defined in namecont.hxx ) When you change the source in the IDE for example then replaceByName is called on the NameContainer, this in-turn fires an event to any listener(s). It just so happens that our friendly BaseMgr has such a listerer instance for each library, and the elementReplaced/elementXXXX methods modify the core in memory classes. how do the BasicManager and the ScriptLibraryContainer/ScriptLibrary classes co-operate. On Document load ================ If the document has Storage, normally the ScriptLibraryContainer is created first, and as we can see above initialisation of the ScriptLibraryContainer ( for a document ) reads in any basic scripts that are stored to the document. Post Document Load ================== Attempting to create a script will result in the library container getting created, if it already exists ( say for example with Libraries/Modules already loaded ) then new libraries/Modules are created in memory. The same classes ( e.g. SfxScriptLibrary ) are used to store the Library/Module relationship ( and copy of the source ) What are all these other classes for e.g. BasicManagerImpl, BasMgrContainerListenerImpl, BasicLibInfo, BasicLibs, BasicManager BasicManagerImpl ( basmgr.cxx ) - internal structure struct LibraryContainerInfo { ::com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer > mxScriptCont; ::com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer > mxDialogCont; OldBasicPassword* mpOldBasicPassword; }; struct BasicManagerImpl { LibraryContainerInfo maContainerInfo; // Save stream data SvMemoryStream* mpManagerStream; SvMemoryStream** mppLibStreams; sal_Int32 mnLibStreamCount; sal_Bool mbModifiedByLibraryContainer; sal_Bool mbError; }; BasicLibInfo - class storing the following info StarBASICRef xLib; - the library String aLibName; - the name String aStorageName; - ? String aRelStorageName; - ? String aPassword; - self explanitory BOOL bDoLoad; - preload? BOOL bReference; - link? BOOL bPasswordVerified; - BOOL bFoundInPath; - ? Reference< XLibraryContainer > mxScriptCont; - uno library storage BasicLibs derived for ( list of library BasicLibInfo ) - with aBasicLibPath memeber. e.g. a list of BasicLibInfo associated with a path. The BasicManager holds instance(s) of the BasicManagerImp & BasicLibs classes so, in the case of a BasicManager created for the document a) SfxObjectShell::InitBasicManager_Impl calls basic::BasicManagerRepository::getDocumentBasicManager( xModel ) which for the initial call actually creates the basic manager ( passing in the storage and pAppBasic ) **note** pAppBasic is actually a pointer to the StdLibrary of application basic b) BasicManager::BasicManger called c) Init() is called, simply just creates instances of BasicLibs and BasicManagerImpl d) ImpCreateStdLib( pParentFromStdLib ) is called to create the standard library. Basically its created, populated and added to the pLibs instance e) after basic::BasicManagerRepository::getDocumentBasicManager( xModel ) creates the basicmanager it tries to bind the library containers ( the uno ones ) if they exist by calling BasicManager::SetLibraryContainerInfo(...) **Note** SetLibraryContainerInfo also creates the listeners etc. to get notified of any changes via the api Excel/Import & Basic ===================== The basic stack is as follows SfxObjectShell::DoLoad ScDocShell::ConvertFrom sc/source/ui/docshell/docsh.cxx * SvxImportMSVBasic::ImportCode_Impl svx/source/msfilter/svxmsbas.cxx SvxImportMSVBasic::Import ImportExcel8::ReadBasic sc/source/filter/excel/excimp8.cxx:310 ImportExcel8::Read sc/source/filter/excel/read.cxx:998 ScImportExcel sc/source/filter/excel/excel.cxx:193 [*] import of dialog is initialted from SvxImportMSVBasic::ImportForms_Impl crafting some new options in xml seems not to screw up basic e.g. a basic wide vba enable flag could be put here Basic/script-lc.xml The relation ship between the code name ( and libraries ) could be put here Basic/Standard/script-lb.xml Basic/script-lc.xml is read from basic/source/uno/namecont.cxx sal_Bool SfxLibraryContainer::init_Impl { ... Parser->setDocumentHandler( ::xmlscript::importLibraryContainer( pLibArray ) ); ... } Basic/Standard/script-lb.xml is read from SfxLibraryContainer::implLoadLibraryIndexFile(..) { ... xParser->setDocumentHandler( ::xmlscript::importLibrary( rLib ) ); ... } both the xmlscript routines are implemented in xmlscript/source/xmllib_imexp/xmllib_import.cxx