1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
;
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()
69 OUString
BasicLibraryNodeImpl::getName( )
71 SolarMutexGuard aGuard
;
77 Sequence
< Reference
< browse::XBrowseNode
> > BasicLibraryNodeImpl::getChildNodes( )
79 SolarMutexGuard aGuard
;
81 std::vector
< Reference
< browse::XBrowseNode
> > aChildNodes
;
83 if ( m_xLibContainer
.is() && m_xLibContainer
->hasByName( m_sLibName
) && !m_xLibContainer
->isLibraryLoaded( m_sLibName
) )
84 m_xLibContainer
->loadLibrary( m_sLibName
);
86 if ( m_pBasicManager
)
88 StarBASIC
* pBasic
= m_pBasicManager
->GetLib( m_sLibName
);
89 if ( pBasic
&& m_xLibrary
.is() )
91 Sequence
< OUString
> aNames
= m_xLibrary
->getElementNames();
92 sal_Int32 nCount
= aNames
.getLength();
93 const OUString
* pNames
= aNames
.getConstArray();
94 aChildNodes
.resize( nCount
);
96 for ( sal_Int32 i
= 0 ; i
< nCount
; ++i
)
98 SbModule
* pModule
= pBasic
->FindModule( pNames
[i
] );
100 aChildNodes
[i
] = new BasicModuleNodeImpl(m_xContext
, m_sScriptingContext
,
101 pModule
, m_bIsAppScript
);
106 return comphelper::containerToSequence(aChildNodes
);
110 sal_Bool
BasicLibraryNodeImpl::hasChildNodes( )
112 SolarMutexGuard aGuard
;
114 bool bReturn
= false;
115 if ( m_xLibrary
.is() )
116 bReturn
= m_xLibrary
->hasElements();
122 sal_Int16
BasicLibraryNodeImpl::getType( )
124 return browse::BrowseNodeTypes::CONTAINER
;
128 } // namespace basprov
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */