Update git submodules
[LibreOffice.git] / scripting / source / basprov / baslibnode.cxx
blob566883757b484841c9d9d25cc400739325e35207
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 <utility>
25 #include <vcl/svapp.hxx>
26 #include <basic/basmgr.hxx>
27 #include <basic/sbstar.hxx>
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::lang;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::script;
36 namespace basprov
40 // BasicLibraryNodeImpl
43 BasicLibraryNodeImpl::BasicLibraryNodeImpl( const Reference< XComponentContext >& rxContext,
44 OUString sScriptingContext, BasicManager* pBasicManager,
45 const Reference< script::XLibraryContainer >& xLibContainer, OUString sLibName, bool isAppScript )
46 :m_xContext( rxContext )
47 ,m_sScriptingContext(std::move( sScriptingContext ))
48 ,m_pBasicManager( pBasicManager )
49 ,m_xLibContainer( xLibContainer )
50 ,m_sLibName(std::move( sLibName ))
51 ,m_bIsAppScript( isAppScript )
53 if ( m_xLibContainer.is() )
55 Any aElement = m_xLibContainer->getByName( m_sLibName );
56 aElement >>= m_xLibrary;
61 BasicLibraryNodeImpl::~BasicLibraryNodeImpl()
66 // XBrowseNode
69 OUString BasicLibraryNodeImpl::getName( )
71 return m_sLibName;
75 Sequence< Reference< browse::XBrowseNode > > BasicLibraryNodeImpl::getChildNodes( )
77 SolarMutexGuard aGuard;
79 std::vector< Reference< browse::XBrowseNode > > aChildNodes;
81 if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_sLibName ) && !m_xLibContainer->isLibraryLoaded( m_sLibName ) )
82 m_xLibContainer->loadLibrary( m_sLibName );
84 if ( m_pBasicManager )
86 StarBASIC* pBasic = m_pBasicManager->GetLib( m_sLibName );
87 if ( pBasic && m_xLibrary.is() )
89 Sequence< OUString > aNames = m_xLibrary->getElementNames();
90 sal_Int32 nCount = aNames.getLength();
91 const OUString* pNames = aNames.getConstArray();
92 aChildNodes.resize( nCount );
94 for ( sal_Int32 i = 0 ; i < nCount ; ++i )
96 SbModule* pModule = pBasic->FindModule( pNames[i] );
97 if ( pModule )
98 aChildNodes[i] = new BasicModuleNodeImpl(m_xContext, m_sScriptingContext,
99 pModule, m_bIsAppScript);
104 return comphelper::containerToSequence(aChildNodes);
108 sal_Bool BasicLibraryNodeImpl::hasChildNodes( )
110 SolarMutexGuard aGuard;
112 bool bReturn = false;
113 if ( m_xLibrary.is() )
114 bReturn = m_xLibrary->hasElements();
116 return bReturn;
120 sal_Int16 BasicLibraryNodeImpl::getType( )
122 return browse::BrowseNodeTypes::CONTAINER;
126 } // namespace basprov
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */