1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_scripting.hxx" 30 #include "baslibnode.hxx" 31 #include "basmodnode.hxx" 32 #include <com/sun/star/script/browse/BrowseNodeTypes.hpp> 33 #include <vos/mutex.hxx> 34 #include <vcl/svapp.hxx> 35 #include <basic/basmgr.hxx> 36 #include <basic/sbstar.hxx> 37 38 39 using namespace ::com::sun::star; 40 using namespace ::com::sun::star::lang; 41 using namespace ::com::sun::star::uno; 42 using namespace ::com::sun::star::script; 43 44 45 //......................................................................... 46 namespace basprov 47 { 48 //......................................................................... 49 50 // ============================================================================= 51 // BasicLibraryNodeImpl 52 // ============================================================================= 53 54 BasicLibraryNodeImpl::BasicLibraryNodeImpl( const Reference< XComponentContext >& rxContext, 55 const ::rtl::OUString& sScriptingContext, BasicManager* pBasicManager, 56 const Reference< script::XLibraryContainer >& xLibContainer, const ::rtl::OUString& sLibName, bool isAppScript ) 57 :m_xContext( rxContext ) 58 ,m_sScriptingContext( sScriptingContext ) 59 ,m_pBasicManager( pBasicManager ) 60 ,m_xLibContainer( xLibContainer ) 61 ,m_sLibName( sLibName ) 62 ,m_bIsAppScript( isAppScript ) 63 { 64 if ( m_xLibContainer.is() ) 65 { 66 Any aElement = m_xLibContainer->getByName( m_sLibName ); 67 aElement >>= m_xLibrary; 68 } 69 } 70 71 // ----------------------------------------------------------------------------- 72 73 BasicLibraryNodeImpl::~BasicLibraryNodeImpl() 74 { 75 } 76 77 // ----------------------------------------------------------------------------- 78 // XBrowseNode 79 // ----------------------------------------------------------------------------- 80 81 ::rtl::OUString BasicLibraryNodeImpl::getName( ) throw (RuntimeException) 82 { 83 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 84 85 return m_sLibName; 86 } 87 88 // ----------------------------------------------------------------------------- 89 90 Sequence< Reference< browse::XBrowseNode > > BasicLibraryNodeImpl::getChildNodes( ) throw (RuntimeException) 91 { 92 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 93 94 Sequence< Reference< browse::XBrowseNode > > aChildNodes; 95 96 if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_sLibName ) && !m_xLibContainer->isLibraryLoaded( m_sLibName ) ) 97 m_xLibContainer->loadLibrary( m_sLibName ); 98 99 if ( m_pBasicManager ) 100 { 101 StarBASIC* pBasic = m_pBasicManager->GetLib( m_sLibName ); 102 if ( pBasic && m_xLibrary.is() ) 103 { 104 Sequence< ::rtl::OUString > aNames = m_xLibrary->getElementNames(); 105 sal_Int32 nCount = aNames.getLength(); 106 const ::rtl::OUString* pNames = aNames.getConstArray(); 107 aChildNodes.realloc( nCount ); 108 Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray(); 109 110 for ( sal_Int32 i = 0 ; i < nCount ; ++i ) 111 { 112 SbModule* pModule = pBasic->FindModule( pNames[i] ); 113 if ( pModule ) 114 pChildNodes[i] = static_cast< browse::XBrowseNode* >( new BasicModuleNodeImpl( m_xContext, m_sScriptingContext, pModule, m_bIsAppScript ) ); 115 } 116 } 117 } 118 119 return aChildNodes; 120 } 121 122 // ----------------------------------------------------------------------------- 123 124 sal_Bool BasicLibraryNodeImpl::hasChildNodes( ) throw (RuntimeException) 125 { 126 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 127 128 sal_Bool bReturn = sal_False; 129 if ( m_xLibrary.is() ) 130 bReturn = m_xLibrary->hasElements(); 131 132 return bReturn; 133 } 134 135 // ----------------------------------------------------------------------------- 136 137 sal_Int16 BasicLibraryNodeImpl::getType( ) throw (RuntimeException) 138 { 139 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 140 141 return browse::BrowseNodeTypes::CONTAINER; 142 } 143 144 // ----------------------------------------------------------------------------- 145 146 //......................................................................... 147 } // namespace basprov 148 //......................................................................... 149