Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / scripting / source / basprov / baslibnode.cxx
blob015334f97ae06fe6abc955f4b6ec6d105891661f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "baslibnode.hxx"
21 #include "basmodnode.hxx"
22 #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
23 #include <comphelper/sequence.hxx>
24 #include <vcl/svapp.hxx>
25 #include <basic/basmgr.hxx>
26 #include <basic/sbstar.hxx>
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::lang;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::script;
35 namespace basprov
39 // BasicLibraryNodeImpl
42 BasicLibraryNodeImpl::BasicLibraryNodeImpl( const Reference< XComponentContext >& rxContext,
43 const OUString& sScriptingContext, BasicManager* pBasicManager,
44 const Reference< script::XLibraryContainer >& xLibContainer, const OUString& sLibName, bool isAppScript )
45 :m_xContext( rxContext )
46 ,m_sScriptingContext( sScriptingContext )
47 ,m_pBasicManager( pBasicManager )
48 ,m_xLibContainer( xLibContainer )
49 ,m_sLibName( sLibName )
50 ,m_bIsAppScript( isAppScript )
52 if ( m_xLibContainer.is() )
54 Any aElement = m_xLibContainer->getByName( m_sLibName );
55 aElement >>= m_xLibrary;
60 BasicLibraryNodeImpl::~BasicLibraryNodeImpl()
65 // XBrowseNode
68 OUString BasicLibraryNodeImpl::getName( )
70 SolarMutexGuard aGuard;
72 return m_sLibName;
76 Sequence< Reference< browse::XBrowseNode > > BasicLibraryNodeImpl::getChildNodes( )
78 SolarMutexGuard aGuard;
80 std::vector< Reference< browse::XBrowseNode > > aChildNodes;
82 if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_sLibName ) && !m_xLibContainer->isLibraryLoaded( m_sLibName ) )
83 m_xLibContainer->loadLibrary( m_sLibName );
85 if ( m_pBasicManager )
87 StarBASIC* pBasic = m_pBasicManager->GetLib( m_sLibName );
88 if ( pBasic && m_xLibrary.is() )
90 Sequence< OUString > aNames = m_xLibrary->getElementNames();
91 sal_Int32 nCount = aNames.getLength();
92 const OUString* pNames = aNames.getConstArray();
93 aChildNodes.resize( nCount );
95 for ( sal_Int32 i = 0 ; i < nCount ; ++i )
97 SbModule* pModule = pBasic->FindModule( pNames[i] );
98 if ( pModule )
99 aChildNodes[i] = new BasicModuleNodeImpl(m_xContext, m_sScriptingContext,
100 pModule, m_bIsAppScript);
105 return comphelper::containerToSequence(aChildNodes);
109 sal_Bool BasicLibraryNodeImpl::hasChildNodes( )
111 SolarMutexGuard aGuard;
113 bool bReturn = false;
114 if ( m_xLibrary.is() )
115 bReturn = m_xLibrary->hasElements();
117 return bReturn;
121 sal_Int16 BasicLibraryNodeImpl::getType( )
123 SolarMutexGuard aGuard;
125 return browse::BrowseNodeTypes::CONTAINER;
129 } // namespace basprov
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */