Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / scripting / source / basprov / basmodnode.cxx
blob145dda2b6e54f16932f3374900ba163f5aa31c98
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 "basmodnode.hxx"
21 #include "basmethnode.hxx"
22 #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
23 #include <osl/mutex.hxx>
24 #include <vcl/svapp.hxx>
25 #include <basic/sbx.hxx>
26 #include <basic/sbstar.hxx>
27 #include <basic/sbmod.hxx>
28 #include <basic/sbmeth.hxx>
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::script;
37 namespace basprov
41 // BasicModuleNodeImpl
44 BasicModuleNodeImpl::BasicModuleNodeImpl( const Reference< XComponentContext >& rxContext,
45 const OUString& sScriptingContext, SbModule* pModule, bool isAppScript )
46 :m_xContext( rxContext )
47 ,m_sScriptingContext( sScriptingContext )
48 ,m_pModule( pModule )
49 ,m_bIsAppScript( isAppScript )
54 BasicModuleNodeImpl::~BasicModuleNodeImpl()
59 // XBrowseNode
62 OUString BasicModuleNodeImpl::getName( )
64 SolarMutexGuard aGuard;
66 OUString sModuleName;
67 if ( m_pModule )
68 sModuleName = m_pModule->GetName();
70 return sModuleName;
74 Sequence< Reference< browse::XBrowseNode > > BasicModuleNodeImpl::getChildNodes( )
76 SolarMutexGuard aGuard;
78 Sequence< Reference< browse::XBrowseNode > > aChildNodes;
80 if ( m_pModule )
82 SbxArray* pMethods = m_pModule->GetMethods().get();
83 if ( pMethods )
85 sal_Int32 nCount = pMethods->Count();
86 sal_Int32 nRealCount = 0;
87 for ( sal_Int32 i = 0; i < nCount; ++i )
89 SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Get( static_cast< sal_uInt16 >( i ) ) );
90 if ( pMethod && !pMethod->IsHidden() )
91 ++nRealCount;
93 aChildNodes.realloc( nRealCount );
94 Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray();
96 sal_Int32 iTarget = 0;
97 for ( sal_Int32 i = 0; i < nCount; ++i )
99 SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Get( static_cast< sal_uInt16 >( i ) ) );
100 if ( pMethod && !pMethod->IsHidden() )
101 pChildNodes[iTarget++] = static_cast< browse::XBrowseNode* >( new BasicMethodNodeImpl( m_xContext, m_sScriptingContext, pMethod, m_bIsAppScript ) );
106 return aChildNodes;
110 sal_Bool BasicModuleNodeImpl::hasChildNodes( )
112 SolarMutexGuard aGuard;
114 bool bReturn = false;
115 if ( m_pModule )
117 SbxArray* pMethods = m_pModule->GetMethods().get();
118 if ( pMethods && pMethods->Count() > 0 )
119 bReturn = true;
122 return bReturn;
126 sal_Int16 BasicModuleNodeImpl::getType( )
128 SolarMutexGuard aGuard;
130 return browse::BrowseNodeTypes::CONTAINER;
134 } // namespace basprov
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */