LibreOffice Module scripting (master) 1
baslibnode.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "baslibnode.hxx"
21#include "basmodnode.hxx"
22#include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
24#include <utility>
25#include <vcl/svapp.hxx>
26#include <basic/basmgr.hxx>
27#include <basic/sbstar.hxx>
28
29
30using namespace ::com::sun::star;
31using namespace ::com::sun::star::lang;
32using namespace ::com::sun::star::uno;
33using namespace ::com::sun::star::script;
34
35
36namespace basprov
37{
38
39
40 // BasicLibraryNodeImpl
41
42
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 )
52 {
53 if ( m_xLibContainer.is() )
54 {
55 Any aElement = m_xLibContainer->getByName( m_sLibName );
56 aElement >>= m_xLibrary;
57 }
58 }
59
60
62 {
63 }
64
65
66 // XBrowseNode
67
68
70 {
71 SolarMutexGuard aGuard;
72
73 return m_sLibName;
74 }
75
76
77 Sequence< Reference< browse::XBrowseNode > > BasicLibraryNodeImpl::getChildNodes( )
78 {
79 SolarMutexGuard aGuard;
80
81 std::vector< Reference< browse::XBrowseNode > > aChildNodes;
82
83 if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_sLibName ) && !m_xLibContainer->isLibraryLoaded( m_sLibName ) )
84 m_xLibContainer->loadLibrary( m_sLibName );
85
86 if ( m_pBasicManager )
87 {
89 if ( pBasic && m_xLibrary.is() )
90 {
91 Sequence< OUString > aNames = m_xLibrary->getElementNames();
92 sal_Int32 nCount = aNames.getLength();
93 const OUString* pNames = aNames.getConstArray();
94 aChildNodes.resize( nCount );
95
96 for ( sal_Int32 i = 0 ; i < nCount ; ++i )
97 {
98 SbModule* pModule = pBasic->FindModule( pNames[i] );
99 if ( pModule )
101 pModule, m_bIsAppScript);
102 }
103 }
104 }
105
106 return comphelper::containerToSequence(aChildNodes);
107 }
108
109
111 {
112 SolarMutexGuard aGuard;
113
114 bool bReturn = false;
115 if ( m_xLibrary.is() )
116 bReturn = m_xLibrary->hasElements();
117
118 return bReturn;
119 }
120
121
123 {
124 return browse::BrowseNodeTypes::CONTAINER;
125 }
126
127
128} // namespace basprov
129
130
131/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
StarBASIC * GetLib(sal_uInt16 nLib) const
SbModule * FindModule(std::u16string_view)
virtual sal_Int16 SAL_CALL getType() override
Definition: baslibnode.cxx:122
css::uno::Reference< css::script::XLibraryContainer > m_xLibContainer
Definition: baslibnode.hxx:46
virtual ~BasicLibraryNodeImpl() override
Definition: baslibnode.cxx:61
virtual css::uno::Sequence< css::uno::Reference< css::script::browse::XBrowseNode > > SAL_CALL getChildNodes() override
Definition: baslibnode.cxx:77
css::uno::Reference< css::container::XNameContainer > m_xLibrary
Definition: baslibnode.hxx:47
BasicLibraryNodeImpl(const css::uno::Reference< css::uno::XComponentContext > &rxContext, OUString sScriptingContext, BasicManager *pBasicManager, const css::uno::Reference< css::script::XLibraryContainer > &xLibContainer, OUString sLibName, bool isAppScript)
Definition: baslibnode.cxx:43
virtual OUString SAL_CALL getName() override
Definition: baslibnode.cxx:69
virtual sal_Bool SAL_CALL hasChildNodes() override
Definition: baslibnode.cxx:110
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: baslibnode.hxx:43
BasicManager * m_pBasicManager
Definition: baslibnode.hxx:45
int nCount
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
int i
unsigned char sal_Bool