Branch libreoffice-5-0-4
[LibreOffice.git] / scripting / source / basprov / baslibnode.cxx
blob3943c3470f7f380ed4081b74b90f45e0cbf7264b
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 <osl/mutex.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;
36 namespace basprov
41 // BasicLibraryNodeImpl
44 BasicLibraryNodeImpl::BasicLibraryNodeImpl( const Reference< XComponentContext >& rxContext,
45 const OUString& sScriptingContext, BasicManager* pBasicManager,
46 const Reference< script::XLibraryContainer >& xLibContainer, const OUString& sLibName, bool isAppScript )
47 :m_xContext( rxContext )
48 ,m_sScriptingContext( sScriptingContext )
49 ,m_pBasicManager( pBasicManager )
50 ,m_xLibContainer( xLibContainer )
51 ,m_sLibName( sLibName )
52 ,m_bIsAppScript( isAppScript )
54 if ( m_xLibContainer.is() )
56 Any aElement = m_xLibContainer->getByName( m_sLibName );
57 aElement >>= m_xLibrary;
63 BasicLibraryNodeImpl::~BasicLibraryNodeImpl()
68 // XBrowseNode
71 OUString BasicLibraryNodeImpl::getName( ) throw (RuntimeException, std::exception)
73 SolarMutexGuard aGuard;
75 return m_sLibName;
80 Sequence< Reference< browse::XBrowseNode > > BasicLibraryNodeImpl::getChildNodes( ) throw (RuntimeException, std::exception)
82 SolarMutexGuard aGuard;
84 Sequence< Reference< browse::XBrowseNode > > aChildNodes;
86 if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_sLibName ) && !m_xLibContainer->isLibraryLoaded( m_sLibName ) )
87 m_xLibContainer->loadLibrary( m_sLibName );
89 if ( m_pBasicManager )
91 StarBASIC* pBasic = m_pBasicManager->GetLib( m_sLibName );
92 if ( pBasic && m_xLibrary.is() )
94 Sequence< OUString > aNames = m_xLibrary->getElementNames();
95 sal_Int32 nCount = aNames.getLength();
96 const OUString* pNames = aNames.getConstArray();
97 aChildNodes.realloc( nCount );
98 Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray();
100 for ( sal_Int32 i = 0 ; i < nCount ; ++i )
102 SbModule* pModule = pBasic->FindModule( pNames[i] );
103 if ( pModule )
104 pChildNodes[i] = static_cast< browse::XBrowseNode* >( new BasicModuleNodeImpl( m_xContext, m_sScriptingContext, pModule, m_bIsAppScript ) );
109 return aChildNodes;
114 sal_Bool BasicLibraryNodeImpl::hasChildNodes( ) throw (RuntimeException, std::exception)
116 SolarMutexGuard aGuard;
118 bool bReturn = false;
119 if ( m_xLibrary.is() )
120 bReturn = m_xLibrary->hasElements();
122 return bReturn;
127 sal_Int16 BasicLibraryNodeImpl::getType( ) throw (RuntimeException, std::exception)
129 SolarMutexGuard aGuard;
131 return browse::BrowseNodeTypes::CONTAINER;
137 } // namespace basprov
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */