Branch libreoffice-5-0-4
[LibreOffice.git] / scripting / source / basprov / basmodnode.cxx
blob6459311034640808fde44e33550be9858592ee12
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;
38 namespace basprov
43 // BasicModuleNodeImpl
46 BasicModuleNodeImpl::BasicModuleNodeImpl( const Reference< XComponentContext >& rxContext,
47 const OUString& sScriptingContext, SbModule* pModule, bool isAppScript )
48 :m_xContext( rxContext )
49 ,m_sScriptingContext( sScriptingContext )
50 ,m_pModule( pModule )
51 ,m_bIsAppScript( isAppScript )
57 BasicModuleNodeImpl::~BasicModuleNodeImpl()
62 // XBrowseNode
65 OUString BasicModuleNodeImpl::getName( ) throw (RuntimeException, std::exception)
67 SolarMutexGuard aGuard;
69 OUString sModuleName;
70 if ( m_pModule )
71 sModuleName = m_pModule->GetName();
73 return sModuleName;
78 Sequence< Reference< browse::XBrowseNode > > BasicModuleNodeImpl::getChildNodes( ) throw (RuntimeException, std::exception)
80 SolarMutexGuard aGuard;
82 Sequence< Reference< browse::XBrowseNode > > aChildNodes;
84 if ( m_pModule )
86 SbxArray* pMethods = m_pModule->GetMethods();
87 if ( pMethods )
89 sal_Int32 nCount = pMethods->Count();
90 sal_Int32 nRealCount = 0;
91 for ( sal_Int32 i = 0; i < nCount; ++i )
93 SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Get( static_cast< sal_uInt16 >( i ) ) );
94 if ( pMethod && !pMethod->IsHidden() )
95 ++nRealCount;
97 aChildNodes.realloc( nRealCount );
98 Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray();
100 sal_Int32 iTarget = 0;
101 for ( sal_Int32 i = 0; i < nCount; ++i )
103 SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Get( static_cast< sal_uInt16 >( i ) ) );
104 if ( pMethod && !pMethod->IsHidden() )
105 pChildNodes[iTarget++] = static_cast< browse::XBrowseNode* >( new BasicMethodNodeImpl( m_xContext, m_sScriptingContext, pMethod, m_bIsAppScript ) );
110 return aChildNodes;
115 sal_Bool BasicModuleNodeImpl::hasChildNodes( ) throw (RuntimeException, std::exception)
117 SolarMutexGuard aGuard;
119 bool bReturn = false;
120 if ( m_pModule )
122 SbxArray* pMethods = m_pModule->GetMethods();
123 if ( pMethods && pMethods->Count() > 0 )
124 bReturn = true;
127 return bReturn;
132 sal_Int16 BasicModuleNodeImpl::getType( ) throw (RuntimeException, std::exception)
134 SolarMutexGuard aGuard;
136 return browse::BrowseNodeTypes::CONTAINER;
142 } // namespace basprov
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */